import { ArgumentsHost , ExceptionFilter } from '@nestjs/common' ; import { Response } from 'express' ; export class ExampleExceptionFilter implements ExceptionFilter { catch ( exception , host ) { const context = host . switchToHttp ( ) ; const response = context . getResponse < Response > ( ) ; const isError = exception instanceof Error ; const status = isError ? 400 : 500 ; const message = isError ? exception . message : exception . toString ( ) ; response . status ( status ) . json ( { statusCode : status , message , } ) ; } }