fix(batch): only fall back to direct Horizon on network-layer errors (#14) - #101
Open
ghzhost wants to merge 1 commit into
Open
fix(batch): only fall back to direct Horizon on network-layer errors (#14)#101ghzhost wants to merge 1 commit into
ghzhost wants to merge 1 commit into
Conversation
…tellarSend#14) batchPaymentApi.send's catch block previously swallowed every error and blindly resubmitted the signed XDR straight to Horizon, bypassing backend validation and risking double-spend when the backend had already broadcast the transaction (the HTTP response was lost). The fix: 1. ApiRequestError gains an optional httpStatus field populated by normalizeApiError from the Axios response status. A missing httpStatus unambiguously identifies a pure network-layer failure (no server response arrived at all). 2. New exported helper isNetworkLayerError(error) encapsulates that check in a single, unit-testable place shared across hooks. 3. useBatchPayment's catch block now calls isNetworkLayerError and only falls back to submitTransaction when it returns true. 4xx (validation/ client), 5xx (server), and 502 (gateway) errors are re-thrown so the caller sees a real error rather than a spurious success. Tests added in useBatchPayment.test.tsx covering: - normal backend-success path (no Horizon call) - pure network error → fallback triggers - 400 validation error → error surfaced, no fallback - 500 server error → error surfaced, no fallback - 422 unprocessable → error surfaced, no fallback - 502 bad gateway → error surfaced, no fallback - isNetworkLayerError unit tests for all variants
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.
Problem (fixes #14)
useBatchPayment'sbatchPaymentApi.sendcatch block previously swallowed every error and blindly resubmitted the already-signed XDR straight to Horizon, regardless of error type.This caused two concrete failure modes:
tx_bad_seqand the user sees a confusing error at exactly the point where the payment actually worked.Fix
src/lib/api.tshttpStatus?: numberfield toApiRequestError, populated bynormalizeApiErrorfrom the Axios response status. A missinghttpStatusunambiguously identifies a pure network-layer failure (no server response arrived).isNetworkLayerError(error)encapsulates the check in one unit-testable place.src/hooks/useBatchPayment.tsisNetworkLayerErrorand only falls back tosubmitTransactionwhen it returnstrue(no HTTP response = backend never received the request).Tests added
src/hooks/useBatchPayment.test.tsx— 10 tests:isNetworkLayerErrorunit tests (with/without status, non-ApiRequestError)All 123 existing tests still pass.