> **Can't find what you're looking for?** Use `search_docs` on the docs MCP server at `https://mpp.dev/api/mcp` to find what you need.

# `Errors` \[Handle payment failures]

Inspect payment errors from `mppx` and choose a safe recovery path.

## Usage

```ts twoslash
import { Errors } from 'mppx'
import { Mppx, tempo } from 'mppx/client'

const client = Mppx.create({ methods: [tempo.charge()], polyfill: false })

client.onPaymentFailed(({ error }) => {
  // [!code hl:start]
  if (error instanceof Errors.PaymentOutcomeUnknownError) {
    console.log(error.challenge.id, error.transactionHash)
    // Reconcile this payment before attempting another one.
  }
  // [!code hl:end]
})
```

`PaymentOutcomeUnknownError` is emitted when a paid retry returns `5xx` or throws. It retains the Challenge and serialized Credential; `transactionHash` is available for push and unsponsored Tempo charges when the final hash can be derived. A thrown retry is still thrown to the caller, with its original error available as `cause` on the event error.

`CredentialReplayedError` extends `VerificationFailedError`. Replayed Credentials receive `402` with an `invalid-challenge` Problem Detail and a fresh Challenge. Reconcile an uncertain outcome before paying that Challenge.

### PaymentLimitExceededError

Client spending controls refuse a payment before creating a Credential. `limit` is `'maxPayment'` for a per-payment cap or `'budget'` for a shared budget. `reason` is `'amount'` when the payment exceeds the cap, `'asset'` when its asset can't be counted, `'intent'` for a Session or subscription, or `'credential'` when a supplied Credential can't be matched to one offered Challenge. See [`Budget.create`](/sdk/typescript/client/Budget.create).

### LegacyUnicodeEscapedChallengeError

The server escaped a Challenge ID-bound parameter as `\\uXXXX`. Upgrade the server; the client refuses the offer before signing because its Credential would fail verification.

`InternalPaymentError.cause` holds the original server error for hooks. The cause is never serialized into Problem Details. Avoid logging raw upstream errors or serialized Credentials.

### BroadcastOutcomeUnknownError

A server broadcast fails without proving whether the node accepted the transaction, and no on-chain transaction receipt arrives before polling stops. The transaction may still be included until `validBefore` (Unix seconds). Look up `transactionHash` before retrying; after `validBefore` passes, a lookup can settle the outcome because the transaction can no longer be included. Without an expiry, continue reconciliation rather than assuming failure.

This is an `Error`, not a `PaymentError`. Server HTTP handlers return a generic `500` `InternalPaymentError` whose `cause` holds this error.

| Property | Type | Description |
| --- | --- | --- |
| `transactionHash` | `` `0x${string}` `` | Hash to look up on chain. |
| `validBefore` | `number \| undefined` | Last inclusion deadline, in Unix seconds. |

### MACH funding errors

`PaymentError.fundingUrl` is `string | undefined`. When present, `toProblemDetails()` includes it as an RFC 9457 extension member. `VerificationFailedError` and `InsufficientBalanceError` accept `fundingUrl` in their options and append `Add funds at <url>` to their message.

On Tempo mainnet, MACH shortfalls link to Tempo Wallet, with the payer and missing amount when known. Session balance errors may link without an amount. Other networks don't receive a MACH onramp link. Present the link to the buyer; don't automatically open or pay it.

* **Charge client:** without `autoSwap`, an eligible MACH route that can't be paid from either MACH or the requested stablecoin throws `InsufficientBalanceError` before signing.
* **Session client:** a MACH channel open or manual top-up without `autoSwap` checks the deposit balance before signing and throws `InsufficientBalanceError` when short.
* **Charge server:** a pre-broadcast failure with a confirmed MACH shortfall becomes `VerificationFailedError`. Existing typed payment errors and uncertain broadcast outcomes keep their original recovery paths. Settled replays remain `CredentialReplayedError` even when the spent balance is low.
* **Session server:** an exhausted MACH channel returns `InsufficientBalanceError`, including from channel charges and SSE responses.

Build your own link with [`machineTokenFundingUrl`](/sdk/typescript/tempo.machineTokenFundingUrl).

### PaymentSimulationError

In a sponsored payment, a fee payer pays network fees for the sender. The sender phase simulates the sender's calls; the sponsored phase simulates the final transaction with that fee payer.

A sponsored payment fails simulation before broadcast. Inspect `phase`, not node error text, to distinguish sender-call failures from failures of the final sponsored envelope. This is also an `Error` exposed as `InternalPaymentError.cause` on server hooks, not a public Problem Details subtype.

| Property | Type | Description |
| --- | --- | --- |
| `feePayer` | `` `0x${string}` \| undefined `` | Fee payer; set only for the sponsored phase. |
| `paymentToken` | `` `0x${string}` \| undefined `` | TIP-20 token for a single transfer or transfer-with-memo call. |
| `phase` | `'sender' \| 'sponsored'` | Sender's calls before sponsorship, or the final fee-payer-billed envelope. |
| `sender` | `` `0x${string}` \| undefined `` | Sender of the simulated transaction. |

### SpendingLimitExceededError

Tempo charge payments and Session opens or top-ups simulate during transaction preparation, before signing. A spending-limit revert throws `SpendingLimitExceededError` with `account`, optional `accessKey`, and the simulation error in `cause`. Raise the limit, wait for its period to reset, or use another key. No payment is signed for this failed preparation.

A token-balance revert throws `InsufficientBalanceError` with the simulation error in `cause` and the available and required token amounts in its message. Fund the account or use another payment account. Other simulation failures keep their original errors; don’t classify them by node error text.

### ZoneSettlementPendingError

`ZoneSettlementPendingError` is thrown when a private payment withdraws funds from a Zone (a private execution environment) but its transfer to Tempo hasn't settled before the client stops waiting. It carries `challengeId`, `senderTags`, and `zoneId`. `senderTag` is available when exactly one candidate remains. The withdrawal can't be undone and may still settle.

| Property | Type | Description |
| --- | --- | --- |
| `challengeId` | `string` | Challenge paid by the withdrawal. |
| `senderTag` | `` `0x${string} \| undefined` `` | Withdrawal tag when exactly one candidate remains. |
| `senderTags` | ``readonly `0x${string}`[]`` | Candidate tags to find on the Zone portal. |
| `zoneId` | `number` | Zone the withdrawal left. |

Call `mppx.createCredential(response)` again with the original `402` response and the same client to resume waiting. Reuse the original Challenge—the client resumes the same withdrawal instead of withdrawing again. See [private payments](/guides/private-payments#handle-slow-settlement).

### FacilitatorResponseError

An x402 facilitator returned a non-`2xx` response or malformed success body from `verify`, `settle`, or `supported`. Inspect `path`, `status`, and the truncated `body` on the server. Failed verification and settlement result bodies remain normal results rather than throwing this error.

### Configurable account errors

* `ConfigurableVouchersUnsupportedError` means a configurable account client tried to open a Session whose Challenge didn't advertise `configurableVouchers`. Use a primitive account or access key, or enable configurable vouchers on a compatible server.
* `SignerConfigChangedError` means the account configuration no longer matches the commitment recorded when the channel opened. Close that channel and open a new one.

## Return type

```ts
type PaymentOutcomeUnknownError = Errors.PaymentError & {
  challenge: Challenge
  credential: string
  transactionHash: string | undefined
}
```

## Parameters

### cause (optional)

* **Type:** `unknown`

Original error for `InternalPaymentError`, `PaymentOutcomeUnknownError`, `BroadcastOutcomeUnknownError`, `PaymentSimulationError`, `SpendingLimitExceededError`, `InsufficientBalanceError`, or `ZoneSettlementPendingError`.

### fundingUrl (optional)

* **Type:** `string`

Funding page for `VerificationFailedError` or `InsufficientBalanceError`; also supported by the protected `PaymentError` constructor for subclasses.

### reason (optional)

* **Type:** `string`

Reason supplied to `CredentialReplayedError`.
