feat(backend): RFC 7807 problem+json error envelope across all routes - #658
Open
RajeshRk18 wants to merge 1 commit into
Open
feat(backend): RFC 7807 problem+json error envelope across all routes#658RajeshRk18 wants to merge 1 commit into
RajeshRk18 wants to merge 1 commit into
Conversation
🤖 Greptile AI Code ReviewGreptile will automatically review this PR (32 file(s) changed). Review gates:
|
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 #635
Every API error now serialises as an RFC 7807
application/problem+jsondocument, built from the existing error-code registry (shared/errorCodes.js):{ "type": "https://github.com/FinChippay/Finchippay-Solution/blob/main/docs/error-codes.md#auth_forbidden", "title": "You do not have permission to access this resource.", "status": 403, "detail": "You do not have permission to access this resource.", "instance": "/api/accounts/x", "code": "AUTH_FORBIDDEN", "correlationId": "…", "error": { "code": "AUTH_FORBIDDEN", "message": "…", "correlationId": "…" } }typederives from the code alone (docs/error-codes.md anchor, code lowercased);titleis the stable registry message;detailis the per-occurrence message;instanceis the request path with the query string dropped.correlationId,details, and the full pre-7807errorobject are kept as RFC-permitted extension members, so existing frontend/SDK consumers keep working unchanged.Changes:
shared/errorCodes.js:formatProblemResponse,problemTypeUri,PROBLEM_CONTENT_TYPE; registry entries untouched (npm run docs:errors:checkpasses).backend/src/middleware/errorHandler.js: body-parse failures, 404, and the terminal handler moved out ofserver.js, all emitting the envelope. Unexpected errors renderSRV_INTERNALwith an allowlist for safedetailmessages — raw internals and stack traces never leak (the olddetails.originalMessageecho of raw messages is removed).sendError/buildProblemResponseset the media type andinstance;zodErrorHandler/validate()and bothexpress-rate-limitlimiters (customhandler,RateLimit-*/Retry-Afterheaders and breach metrics preserved) emit the envelope;turretsServer.jsshares the same terminal handler.res.status().json({...})bodies ontosendError/createError, statuses preserved. Protocol-mandated shapes left intact: health probes,parsePayment's documented chat-UI contract, SEP-24/38 pass-throughs.backend/__tests__/errorEnvelope.test.js(13 tests: 400 validation, 401, 403, 404, 400 bad JSON, 413, 429, 500 sanitisation,createError); 13 existing assertions updated to the new shape.Verification: envelope + error-code suites pass (83 tests); full unit run matches the
mainbaseline exactly (the 29 failing suites onmaincome from a pre-existing@stellar/stellar-sdkESM/Jest issue, unrelated); backend lint reports only the pre-existing error insrc/services/notificationService.js.