feat: add structured error response format with error codes#949
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
|
@dinahmaccodes Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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.
Structured Error Response Format Implementation
This PR implements a standardized error response format across all backend API endpoints with error codes, correlation IDs, and comprehensive error handling.
Changes Made
✅ Error Response Schema
StandardErrorResponseDtowith all required fields (success, statusCode, errorCode, message, timestamp, path, correlationId)✅ Error Code System
CATEGORY_NNN(AUTH_001, VAL_002, DB_001, etc.)error-codes.jsonconfiguration with 17 predefined error codes across 7 categories (AUTH, AUTHZ, VAL, DB, RPC, RATE, SYS)ErrorCodeRegistryservice for centralized error code management✅ Global Exception Filter
EnhancedExceptionFilterreplacing old filters✅ Error Documentation
ERROR_HANDLING.mddocumentationgenerate-error-docsscript for auto-generating error code documentation in Markdown and JSON formatsnpm run generate:error-docs✅ Custom Application Errors
ApplicationExceptionclass with error code support.withContext(key, value)✅ Backward Compatibility
Error Code Categories
Example Error Response
{ "success": false, "statusCode": 400, "errorCode": "VAL_001", "message": "Validation failed. Please check your input.", "timestamp": "2024-01-15T10:30:00.000Z", "path": "/api/v2/goals", "correlationId": "550e8400-e29b-41d4-a716-446655440000", "errors": [ { "field": "goalName", "value": "", "constraints": { "isNotEmpty": "goalName should not be empty" } } ] }Files Changed
backend/src/common/config/error-codes.json- Error code configurationbackend/src/common/dto/standard-error-response.dto.ts- Standardized DTOsbackend/src/common/services/error-code-registry.service.ts- Registry servicebackend/src/common/exceptions/application.exception.ts- Custom exception classbackend/src/common/filters/enhanced-exception.filter.ts- Unified exception filterbackend/src/common/dto/api-error-response.dto.ts- Updated existing DTOsbackend/src/main.ts- Integrated new filterbackend/src/scripts/generate-error-docs.ts- Documentation generatorbackend/docs/ERROR_HANDLING.md- Complete documentationbackend/package.json- Added script, fixed dependenciesTesting
The error handling system has been integrated and maintains backward compatibility. All existing error flows continue to work while providing enhanced error information.
Checklist
Closes #900