feat: enforce structured error response format#149
Open
elijah4196 wants to merge 1 commit into
Open
Conversation
- Fix SERVICE_UNAVAILABLE to return HTTP 503 (was 500) - Add AuthError alias export for AuthenticationError - Add explicit no-stack comment in errorHandler response body - Add 17 unit tests for all custom error classes via errorHandler closes Pidoko257#108
|
@elijah4196 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.
feat: enforce structured error response format (#108)
Summary
Standardizes API error responses across the ProxyPay codebase. All error responses follow
{ code, message, details?, requestId }with supporting fieldsmessage_en,timestamp, andstatusCode. This PR fills the remaining gaps from the existing error handler infrastructure.Changes
src/constants/errorCodes.tsSERVICE_UNAVAILABLEto return HTTP 503 (was incorrectly returning 500)src/utils/errors.tsAuthErroras an exported alias forAuthenticationErrorfor API compatibilitysrc/middleware/errorHandler.tsstackis intentionally excluded from all response bodies (logged server-side only)src/tests/customErrors.test.ts(new)ValidationError,NotFoundError,AuthenticationError,AuthError,AuthorizationError,ConflictError,BusinessLogicErrorcode,{ code, message, timestamp }fields present,stackabsent from response in both production and development,detailsstripped in production,requestIdforwarded from error object and request objectError Response Format
All error responses follow:
{ "code": "INVALID_INPUT", "message": "Invalid input provided", "message_en": "Invalid input provided", "timestamp": "2026-01-01T00:00:00.000Z", "requestId": "req-abc-123", "details": { "field": "phoneNumber" } }detailsis omitted in production.requestIdis omitted if not present.Custom Error Classes
ValidationErrorINVALID_INPUT(configurable)AuthenticationError/AuthErrorUNAUTHORIZEDAuthorizationErrorFORBIDDENNotFoundErrorNOT_FOUNDConflictErrorCONFLICTBusinessLogicErrorINTERNAL_ERRORSERVICE_UNAVAILABLEcloses #108