Use @Catch() with no argument to intercept all exceptions including ORM errors. Branch on the exception type to map specific ORM error codes to semantic HTTP status codes — EntityNotFoundError to 404, unique constraint violations (code 23505) to 409, foreign key violations (code 23503) to 400. Log unknown DB errors server-side and return a generic 500.
EntityNotFoundError (TypeORM) — map to 404 Not Found.
QueryFailedError code 23505 (Postgres unique violation) — map to 409 Conflict.
QueryFailedError code 23503 (Postgres foreign key violation) — map to 400 Bad Request.
QueryFailedError code 23502 (Postgres not null violation) — map to 400 Bad Request.
Always log unexpected database errors with the full stack — never silently swallow them.
You have a NestJS controller that calls a TypeORM repository. If the repository throws a QueryFailedError, how would you use a global exception filter to return a 400 Bad Request instead of a 500?
Walk me through the steps to create a global filter that catches any EntityNotFoundError from TypeORM and maps it to a 404 response.
We noticed that some database constraint violations are bubbling up as 500 errors in production. How would you modify the existing global filter to differentiate between unique constraint violations and foreign key violations, returning appropriate HTTP status codes?
During a recent feature rollout, a new entity caused a QueryFailedError that wasn't being caught by our filter. What debugging steps would you take to identify why the filter missed it, and how would you fix it?
Our service is part of a larger microservices ecosystem where each service has its own NestJS app. How would you design a reusable global filter library that standardizes DB/ORM exception-to-HTTP mapping across services, considering versioning and shared error contracts?
When handling high‑throughput API traffic, the global filter adds noticeable latency. What profiling techniques would you use to measure its impact, and what refactoring could reduce overhead while preserving correct error translation?
The company plans to migrate from TypeORM to Prisma across multiple teams. How would you evolve the existing global exception filter strategy to accommodate both ORMs during the transition, ensuring consistent HTTP responses and minimal disruption?
Leadership wants a unified error handling policy that includes logging, alerting, and client‑friendly messages for all data‑layer failures. Describe how you would architect this policy at the organization level, integrating NestJS filters, centralized logging, and cross‑service error schemas.