📌 Task: [NESTJS] Setup Global Exception Filters
📝 Description
We need to implement a Global Exception Filter in our NestJS application to ensure consistent and centralized error handling across all modules. This will help improve maintainability, debuggability, and developer/user experience by standardizing how errors are caught and returned in HTTP responses.
🎯 Goals
-
Create a global exception filter that handles:
HttpException
UnauthorizedException, ForbiddenException, etc.
- Unhandled exceptions (e.g., uncaught
Error)
-
Format error responses consistently (e.g., including timestamp, path, status code, error message, etc.)
-
Ensure logging is done for critical exceptions (use NestJS logger or a custom logger if applicable)
-
Apply the global filter using app.useGlobalFilters() in the main bootstrap file
-
Optionally handle and log validation errors from class-validator and class-transformer
📁 Expected Folder/Files
src/common/filters/http-exception.filter.ts (suggested location)
main.ts (for global registration)
✅ Acceptance Criteria
🔧 Example Response Format
{
"statusCode": 400,
"timestamp": "2025-06-03T12:00:00.000Z",
"path": "/api/example",
"message": "Bad Request"
}
📌 Task: [NESTJS] Setup Global Exception Filters
📝 Description
We need to implement a Global Exception Filter in our NestJS application to ensure consistent and centralized error handling across all modules. This will help improve maintainability, debuggability, and developer/user experience by standardizing how errors are caught and returned in HTTP responses.
🎯 Goals
Create a global exception filter that handles:
HttpExceptionUnauthorizedException,ForbiddenException, etc.Error)Format error responses consistently (e.g., including timestamp, path, status code, error message, etc.)
Ensure logging is done for critical exceptions (use NestJS logger or a custom logger if applicable)
Apply the global filter using
app.useGlobalFilters()in the main bootstrap fileOptionally handle and log validation errors from class-validator and class-transformer
📁 Expected Folder/Files
src/common/filters/http-exception.filter.ts(suggested location)main.ts(for global registration)✅ Acceptance Criteria
HttpExceptionFilteris created with support for multiple types of exceptionsLogger.error)main.ts🔧 Example Response Format
{ "statusCode": 400, "timestamp": "2025-06-03T12:00:00.000Z", "path": "/api/example", "message": "Bad Request" }