import { ArgumentsHost , Catch , ExceptionFilter , HttpException } from '@nestjs/common' ; import { Response } from 'express' ; @ Catch ( HttpException ) export class HttpExceptionFilter implements ExceptionFilter { catch ( exception , host ) { const ctx = host . switchToHttp ( ) ; const response = ctx . getResponse < Response > ( ) ; const status = exception . getStatus ( ) ; const error = exception . getResponse ( ) ; response . status ( status ) . json ( error ) ; } }