Standardize API error response format to { error: { code, message, de… - #203
Open
Armolas wants to merge 1 commit into
Open
Standardize API error response format to { error: { code, message, de…#203Armolas wants to merge 1 commit into
Armolas wants to merge 1 commit into
Conversation
…tails? } } Consolidates six previously-divergent error shapes (AppError's handleError, AuthController's private duplicate, formatValidationErrors/validateDTO, handleOnChainError, and app.ts's global handler) into one contract across every controller, middleware, and the global Express error handler. Renames ErrorType to double as the default wire code, adds an optional per-call-site code override, centralizes NODE_ENV-gated internal error messages, and fixes MarketplaceController's submit endpoints to classify on-chain errors via handleOnChainError like their sibling controllers.
|
@Armolas 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.
Consolidates six previously-divergent error shapes (AppError's handleError, AuthController's private duplicate, formatValidationErrors/validateDTO, handleOnChainError, and app.ts's global handler) into one contract across every controller, middleware, and the global Express error handler.
Description
Standardizes all API error responses to
{ error: { code, message, details? } }.AppError'sErrorTypeis renamed to double as the default wire code (e.g.NOT_FOUND_ERROR→NOT_FOUND,AUTHENTICATION_ERROR→UNAUTHORIZED), with an optional per-call-site code override for specific cases (SONG_NOT_AVAILABLE,MALWARE_DETECTED,WALLET_NOT_CONNECTED). A newRATE_LIMITED/429 category was added since none of the existing categories fit rate-limit responses.handleError()/handleOnChainError()inutils/helpers.tsare now the single canonical serialization path, withNODE_ENV-gated messages so internal errors never leak details in production. All 11 controllers, 4 middleware files, andapp.ts's global handler/404/circuit-breaker were converted.Along the way this fixed two real bugs the standardization surfaced:
AuthControllerhad its own privatehandleErrorduplicate that silently droppedAppErrortype/details on 9 of its 10 methods (deleted, now routes through the shared helper); andMarketplaceController.submitListing/submitBuywere never wired tohandleOnChainErrorlike their sibling on-chain endpoints (SongController.submitMint,ArtistOnChainController.submitSetup), so Soroban/XDR errors weren't being classified or given a retryable-aware status code.Fixes #121
Type of change
Checklist: