Skip to content

Errors

How Cash App failures surface in React and what to do at each step.

How errors surface

  1. Hook error stateuseCashAppSupportedAssets().error, useCashAppOrder().error, amount validation via useCashAppAmount().error.
  2. Thrown / rejected promisescreateOrder / refetch also reject.
  3. EventsuseOnCashAppOrderFailed and useOnCashAppOrderExpired are not errors, but you must handle them in UI.

Amount validation errors

useCashAppAmount().error is an AmountValidationError ({ code, message, metadata }), not a string. Switch on code for i18n:

tsx
import type { AmountValidationError } from '@swapped/connect-sdk'
import { useCashAppAmount } from '@swapped/connect-sdk/react'

function AmountError() {
  const { error } = useCashAppAmount()
  if (!error) return null

  const text = translateAmountError(error)
  return <p>{text}</p>
}

function translateAmountError(error: AmountValidationError): string {
  switch (error.code) {
    case 'below_min':
      return `Min amount ${error.metadata.formattedMinAmount}`
    case 'above_spendable':
      return `Max amount ${error.metadata.formattedMaxAmount}`
    case 'above_balance':
      return `Balance is ${error.metadata.formattedBalanceAmount}`
    default:
      return error.message
  }
}

Typed SDK failures are ConnectSdkError with a stable code:

tsx
import { ConnectSdkError, ConnectSdkErrorCode } from '@swapped/connect-sdk'
import { useCashAppOrder } from '@swapped/connect-sdk/react'

function CreateWithErrors() {
  const { createOrder, error, isCreating } = useCashAppOrder()

  async function onSubmit() {
    try {
      await createOrder()
    } catch (err) {
      if (
        err instanceof ConnectSdkError &&
        err.code === ConnectSdkErrorCode.SESSION_NOT_ACTIVE
      ) {
        // Call restartSession() via useSwappedConnectClient()
      }
    }
  }

  return (
    <div>
      {error && <p>{error.message}</p>}
      <button type="button" disabled={isCreating} onClick={() => void onSubmit()}>
        Pay
      </button>
    </div>
  )
}

When things fail in the flow

StepWhat goes wrongHow you see itWhat to do in UI
Mount hooksOutside CashAppProviderREACT_CASH_APP_PROVIDER_REQUIREDWrap with the provider
Load assetsAPI / network failureassets error / API_ERRORRetry refetch
Create orderIncomplete selectionCASH_APP_SELECTION_INCOMPLETE (createOrder() only)Select asset and amount, or pass a request
Create orderSession already completedSESSION_NOT_ACTIVErestartSession() first
Create orderSession not loadedSESSION_REQUIREDloadSession()
Create orderAPI rejectionAPI_ERRORFix amount / retry
WaitingPayment faileduseOnCashAppOrderFailed / isFailedFailed UI; create a new order
WaitingTimed outuseOnCashAppOrderExpired / isExpiredToast + navigate back; create a new order
After successCreate again without restartSESSION_NOT_ACTIVErestartSession()

Block amounts below minAmountFiat with useCashAppAmount before createOrder.

Error code reference

CodeWhen it happensWhat to do
REACT_CASH_APP_PROVIDER_REQUIREDHook used outside CashAppProviderWrap with CashAppProvider
CASH_APP_SELECTION_INCOMPLETEcreateOrder() without asset / amountComplete selection first, or pass a request
SESSION_REQUIREDNo loaded sessionCall loadSession()
SESSION_NOT_ACTIVESession cannot accept a new paymentrestartSession() before createOrder
API_ERRORAssets / create failureRetry
CLIENT_DESTROYEDClient already destroyedCreate a new client