import {
  ArgumentsHost,
  Catch,
  ExceptionFilter,
  NotFoundException,
} from "@nestjs/common";

@Catch(NotFoundException)
export class NotFoundInterceptor implements ExceptionFilter {
  constructor() {}

  catch(exception: NotFoundException, host: ArgumentsHost) {
    const ctx = host.switchToHttp();
    const response = ctx.getResponse();
    const exceptionResponse = exception.getResponse() as any;
    if (exceptionResponse.custom) {
      delete exceptionResponse.custom;
      return response.status(404).json(exceptionResponse);
    }
    response.status(404).json(exceptionResponse);
  }
}
