feat: add centralized error handling with error codes and validation …#116
Merged
memplethee-lab merged 1 commit intoJul 22, 2026
Merged
Conversation
…details - Add ErrorCode enum for consistent error identification - Add custom exception classes (AppException, NotFoundException, etc.) with error codes - Update GlobalExceptionFilter to include error codes in responses - Add field-level validation error extraction for 400 responses - Extract Sentry reporting and logging into private helper methods - Use x-request-id header as correlation ID when available
10 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #107
What
Adds a centralized error handling module with custom exception classes, error codes, and field-level validation error responses.
Changes
src/common/errors/error-codes.ts—ErrorCodeenum for consistent programmatic error identification (NOT_FOUND,UNAUTHORIZED,VALIDATION_ERROR,CONFLICT, etc.)src/common/errors/app.exception.ts— BaseAppExceptionclass extendingHttpExceptionwith anerrorCodefield, plus convenience subclasses:NotFoundException,UnauthorizedException,ForbiddenException,BadRequestException,ConflictException,RateLimitExceptionsrc/common/filters/global-exception.filter.ts— Updated to:errorCodein all error responsesx-request-idheader as correlation ID when presentsrc/common/index.ts— Re-exports new exception classes and error codesError Response Format
All errors now return:
{ "statusCode": 400, "errorCode": "VALIDATION_ERROR", "message": "Validation failed", "errors": { "email": ["email must be an email"] }, "correlationId": "...", "timestamp": "2026-07-21T...", "path": "/api/v1/auth/register" } Validation errors, 401, 403, 404, and 409 all map to their correct HTTP status codes with matching errorCode values. Stack traces remain hidden in production, visible in development. Why Standardizes error responses across the API so clients can handle errors programmatically using errorCode instead of parsing message strings. Existing services using NestJS built-in exceptions continue to work unchanged — the filter maps their status codes to error codes automatically. closes #107