fix(tx-broadcast): use 422 over 502 to bypass CF error-page interception#305
Merged
Merged
Conversation
In-VPS curl against the freshly-deployed PR #304 image confirms the route correctly returns the structured envelope: status: 502 content-type: application/json; charset=utf-8 body: {"error":{"code":"TX_FAILED_ON_CHAIN","message":"...", "signature":"...","err":{"InstructionError":[0,{"Custom":1}]}}} But the same request via `https://sipher-api.sip-protocol.org/api/tx/broadcast` returns a Cloudflare-branded `502 Bad gateway` HTML page — CF's default behavior is to replace the origin's response body for 5xx status codes. The FE never sees our JSON envelope. Switching the status to 422 (Unprocessable Entity) bypasses CF's error substitution. The semantics also fit better: the request was syntactically valid; the on-chain program could not process it. The body shape is unchanged. Updates the corresponding route test to expect 422. 10 sendWithRetry / 13 tx-broadcast tests pass. Typecheck clean across root, sdk, app, agent.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
Summary
Final follow-up to #299. PR #304 normalized the polling-fallback rejection so the route catches
TransactionFailedOnChainErrorand emits a structured envelope — verified working via in-VPS curl:But the same request via
https://sipher-api.sip-protocol.org/api/tx/broadcastreturns a Cloudflare-branded502 Bad gatewayHTML page — CF's default behavior is to replace origin's body for 5xx codes. The FE never sees our JSON envelope.This PR switches the status to 422 Unprocessable Entity, which CF passes through unchanged. The semantics also fit: the request was syntactically valid; the on-chain program could not process it.
Test plan
pnpm typecheckclean across root + sdk + app + agentpnpm vitest run tests/routes/tx-broadcast.test.ts— 13 passed422 TX_FAILED_ON_CHAINenvelope visible end-to-end through Cloudflare.Notes
error.codecontinue to work; consumers branching on numeric status need to add 422 to their "tx failed at program level" bucket.