Repository navigation
fix: surface response encoding errors instead of bare 500 {} - #275
Draft
ralph-bitgo[bot] wants to merge 2 commits into
Draft
ralph-bitgo[bot] wants to merge 2 commits into
ralph-bitgo[bot] wants to merge 2 commits into
Conversation
typed-express-router validates every outbound response against its io-ts codec in res.sendEncoded() and falls back to encodeErrorFormatter when the payload fails that check. The library default swallows the validation error and replies with HTTP 500 and an empty JSON body, which is what customers hit from POST /wallet/generate while the WCN-2395 permission bug left advanced-wallet creators view-only: the wallet was created on the backend, but MBE returned a bare 500 {} with nothing actionable in the response or the server logs. Add a customEncodeErrorFormatter that logs the real error (message, stack, and request context) and returns { error, details } in the response body, matching the documented 500 ErrorResponse shape, and wire it into every typed router (MBE, AWM, and the health check routers) alongside the existing decode error formatter. Ticket: WCN-2396 Session-Id: 055eae11-5e57-4df7-8a1e-f8148946b128 Task-Id: 0aaa81ad-1de6-4466-96fb-681ce47e5a15
Cover the new encode error formatter both end to end and at unit level: a wallet/add response that omits a required field (as produced by the WCN-2395 permission bug) must produce a 500 with a descriptive { error, details } body plus a server-side log line naming the failed route, instead of the bare 500 {} MBE previously returned. The end-to-end test reproduces the bare-500 failure against the pre-fix router wiring. Ticket: WCN-2396 Session-Id: 055eae11-5e57-4df7-8a1e-f8148946b128 Task-Id: 0aaa81ad-1de6-4466-96fb-681ce47e5a15
This branch has not been deployed
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.
What
customEncodeErrorFormatterinsrc/shared/errorFormatters.ts: when aresponse payload fails its io-ts codec check in
typed-express-router'sres.sendEncoded(), it logs the real error (message, stack, and requestcontext: method, URL, api name) and returns
{ error: 'Internal Server Error', details: <real message> }in the 500body — matching the documented 500
ErrorResponseshape.encodeErrorFormatter: customEncodeErrorFormatterinto everycreateRoutercall site alongside the existing decode formatter: the MBEAPI router, both MBE health routers, and the AWM API/health routers.
generateWallet.test.tsmakeswallet/addreturn a wallet omitting a required field (as WCN-2395-inducedresponses do) and asserts a descriptive 500 body plus a server-side log
line; this test fails with the bare
500 {}on pre-fix code. Unit tests inerrorFormatters.test.tspin the formatter contract (log content and bodyshape, including the non-
Errorfallback).Why
Customers creating
type: advancedwallets hit the WCN-2395 permission bug(creator stuck at view-only because UMS rejects
walletType: advanced): thewallet is created on the backend, but the
/wallet/addresponse then violatesMBE's response schema, and
typed-express-routersilently swaps the realvalidation error for a bare
HTTP 500 {}— no error body, no server log,nothing actionable for the customer or for on-call (originally reported by
AKM as a secondary symptom of WCN-2395). The library's default
encodeErrorFormatteris() => ({})and MBE only overrode the decode-sideformatter, so the encode side stayed on library defaults.
This is the ticket's immediate/diagnostic fix: every future schema-violating
response becomes debuggable — the client sees which response codec failed and
operators get the full error with stack in the logs — independent of the
upstream WCN-2395 fix. Once WCN-2395 lands upstream, the original symptom
disappears on its own, but this diagnostic layer stays valuable for any
future response-shape regression.
The root fix (UMS enum + wallet-platform retry/DLQ handling) lives in
WCN-2395 and is out of scope for this repo. I deliberately did not relax the
required fields in
generateWalletRoute.tstot.partial: the exactmismatching field still needs live confirmation, and weakening the declared
contract would mask future server-side bugs.
Test plan
npm test— full suite: 442 passing, including the new regression test(verified it fails with the bare
500 {}against pre-fix wiring) andthe formatter unit tests
npm run lint— cleannpm run build(tsc) — cleanscripts/check-openapi-masterExpress.sh— OpenAPI spec in sync (noroute definitions changed)
Ticket: WCN-2396