Tx failed error - #1526
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Adds structured Horizon transaction-submission errors and accessors for result codes and XDR results.
Changes:
- Introduces and exports
TransactionFailedError. - Normalizes synchronous and asynchronous submission failures.
- Updates types, tests, generated references, and changelog.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
src/errors/transaction_failed.ts |
Implements the new error type and accessors. |
src/errors/index.ts |
Exports the new error. |
src/horizon/server.ts |
Maps submission failures to SDK errors. |
src/horizon/horizon_api.ts |
Makes operation result codes optional. |
test/unit/server_transaction.test.ts |
Tests submission error handling. |
docs/reference/errors.md |
Documents the new error API. |
docs/reference/network-horizon.md |
Regenerates Horizon references. |
CHANGELOG.md |
Describes behavior and migration changes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Ryang-21
marked this pull request as ready for review
July 14, 2026 22:58
fnando
reviewed
Jul 16, 2026
fnando
approved these changes
Jul 16, 2026
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
This adds
TransactionFailedError, a new error type raised byHorizon.Server.submitTransactionandsubmitAsyncTransactionwhen Horizon rejects a transaction, and fixes the submission error path so SDK error types are actually thrown.TransactionFailedErrorextendsBadResponseErrorand adds two accessors, mirroring the ergonomics of the Go SDK'shorizonclient.Error:getResultCodes()— returns the{ transaction, operations }result codes directly, e.g.{ transaction: "tx_failed", operations: ["op_underfunded"] }. Horizon omitsoperationsfor transaction-level failures liketx_bad_seq(verified against a live network), so the accessor normalizes it to[]and guarantees an array.getTransactionResult()— decodesextras.result_xdrinto anxdr.TransactionResult, giving structured access to per-operation results without touching base64 (ornullif Horizon sent noresult_xdr).Alongside that:
toSubmissionError()helper: responses carrying Horizon result codes becomeTransactionFailedError, any other HTTP error (rate limit, server error, the async endpoint's distinct 400 payload) becomesBadResponseError, and genuine network errors (DNS, timeout, socket) still pass through untouched. The original HTTP client error is preserved aserr.cause, soresponse.headers,config, and axios-specific fields remain reachable.Federation.Server._sendRequest:resolveAddress,resolveAccountId,resolveTransactionId, andforDomainnow also reject HTTP failures withBadResponseError(original error ascause), with themaxContentLengthsize-limit behavior unchanged.HorizonApi.TransactionFailedResultCodesgained the transaction result codes it was missing:tx_bad_sponsorship,tx_bad_min_seq_age_or_gap,tx_malformed,tx_soroban_invalid, andtx_frozen_key_accessed.result_codes.operationsstays typed as required for backwards compatibility even though Horizon can omit it; making it optional is a source-breaking type change deferred to the next major (Make TransactionFailedExtras result_codes.operations optional (breaking type fix) #1527).Why
Fixes #413 — a request from 2020 for a simple way to get error codes out of a failed submission, instead of digging through
err.response.data.extras.result_codes.Fixes #1437 — the root cause that made this worse than the original ask: the documented behavior of rejecting with
BadResponseErrornever actually happened. The catch handlers'instanceof Errorcheck passed raw HTTP client errors straight through, since they areErrorinstances — the wrapping branch was unreachable, in both the Horizon submit methods and the Federation resolution methods. So consumers have been coding against an undocumented rejection shape with no SDK type to narrow on, no accessors, and no XDR decoding.Note for reviewers: this is observable-behavior-changing even though no TypeScript API breaks.
err.response.dataanderr.response.statusare unchanged, but the error message text differs and HTTP-client-specific fields moved toerr.cause. The changelog spells out the migration details. Verified end-to-end against a local quickstart network across four scenarios: op-level failure (op_underfunded), tx-level failure (tx_bad_seq), the async endpoint, and a successful submission.🤖 Generated with Claude Code