Skip to content

fix(sdk): answer 502 when the facilitator gives no answer - #43

Open
azf20 wants to merge 1 commit into
mainfrom
sdk/settle-transport-502
Open

azf20 wants to merge 1 commit into
mainfrom
sdk/settle-transport-502

Conversation

@azf20

@azf20 azf20 commented Oct 2, 2026

Copy link
Copy Markdown
Collaborator

radiusPayments answers 502 (facilitator_error) when a verify, settle or /supported call fails without the facilitator's own answer.

Problem: @x402/core turns any facilitator error other than FacilitatorResponseError into a 402: a dropped connection, or an error page (e.g. a gateway 504) instead of an x402 body. Settling before the handler (the default), it even comes back as a fresh challenge. A buyer reads 402 as "rejected, nothing moved", but the settle may have reached the chain, so paying again can charge twice.

Change: withUnknownOutcomes (hono/facilitator.ts) wraps the facilitator, built-in or self-hosted. It rethrows those failures as FacilitatorResponseError, which core passes through and the middleware maps to 502. VerifyError and SettleError (the facilitator's own answers) still give 402. A rejected API key at /supported is now 502 rather than 500.

Verified: 5 new tests in hono.test.ts: an error page at settle, a failed connection, settle: 'after' at settle and at verify, and a facilitator rejection staying 402. The four 502 cases fail without the wrapper. 135 SDK and 31 CLI tests pass; typecheck and build pass.

Makes the recovery policy in dev-docs #129 (502 = outcome unknown, 402 = no money moved) true.

🤖 Generated with Claude Code

A verify or settle call that fails without the facilitator's own response
(network error, non-x402 error body) was reported as 402, which buyers read
as a definite rejection although a settle may have reached the chain.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@github-actions

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

🦋 Changeset detected

Latest commit: b5068d7

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
radius-sdk Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant