I'm a junior full-stack developer from Alexandria, Egypt. In my last post I showed the interceptor that makes every successful FaceMark response one shape. This is the other half: the global exception filter that makes every failed response one shape too, and decides what clients get to learn from a failure.
FaceMark is my face-recognition attendance project (NestJS API, Python AI service, MySQL). Here's the filter, trimmed:
// src/common/filters/http-exception.filter.ts @Catch ( ) export class HttpExceptionFilter implements ExceptionFilter { catch ( exception : any , host : ArgumentsHost ) { const ctx = host . switchToHttp ( ) ; const response = ctx . getResponse < Response > ( ) ; const request = ctx . getRequest < Request > ( ) ;
let status = exception instanceof HttpException ? exception . getStatus ( ) : HttpStatus . INTERNAL_SERVER_ERROR ;
// TypeORM database errors get their own treatment if ( exception instanceof QueryFailedError ) { status = HttpStatus .…