Error Handling

Error Handling

The API uses standard HTTP status codes and returns structured error responses.

HTTP status codes

HTTP StatusDescription
200Success
400Invalid argument or failed precondition
401Authentication error (malformed credentials)
403Permission denied (missing or invalid API key)
404Resource not found
409Conflict (e.g. idempotency key collision)
500Internal server error
503Service unavailable
504Request timeout

Error response format

All errors return a JSON object with message and code fields:

{
  "message": "A human-readable description of the error.",
  "code": 3
}

The code field is the underlying gRPC status code number.

Validation errors

Invalid request parameters return HTTP 400 with a message indicating the problematic field:

HTTP/1.1 400 Bad Request
{
  "message": "Invalid argument at \"email\": This must be a valid email address.",
  "code": 3
}

Resource not found

Requesting a resource that doesn't exist returns HTTP 404:

HTTP/1.1 404 Not Found
{
  "message": "Resource \"accounts/acct_ACCOUNT_ID/customers/cus_INVALID\" (of type \"Customer\") not found.",
  "code": 5
}

Idempotency errors

If two concurrent requests use the same idempotency key, the second request returns HTTP 409:

HTTP/1.1 409 Conflict
{
  "message": "Another request with idempotency key \"fb_idem_key_...\" is in progress.",
  "code": 10
}

If a request reuses an idempotency key with a different request body, the API returns HTTP 400:

HTTP/1.1 400 Bad Request
{
  "message": "Mismatch between stored request body for idempotency key and received request body. When retrying idempotent requests, please ensure the request body is identical.",
  "code": 3
}

Payment errors

When a payment fails, the payment intent's response includes a payment_error object with more detail:

Failure codes

CodeDescription
UNKNOWNAn unknown internal error occurred
DEVICE_BUSYThe payment device is performing another operation
DEVICE_OFFLINECannot reach the payment device
DEVICE_OPERATION_CANCELLEDThe operation was cancelled by the operator on the device
DEVICE_OPERATION_EXPIREDThe operation did not complete within 2 minutes
PAYMENT_METHOD_PROVIDER_DECLINEDeclined by the issuer or customer
PAYMENT_METHOD_PROVIDER_TIMEOUTTimeout from the payment provider
PAYMENT_METHOD_NOT_AVAILABLEPayment method is temporarily unavailable

Decline codes

When the failure code is PAYMENT_METHOD_PROVIDER_DECLINE, a more specific decline_code is included:

Decline CodeDescription
DO_NOT_HONORDeclined for an unknown reason
INSUFFICIENT_FUNDSNot enough funds on the card
CARD_VELOCITY_EXCEEDEDCard usage limits exceeded
TRANSACTION_NOT_ALLOWEDTransaction type not permitted
INCORRECT_NUMBERInvalid card number
INCORRECT_CVCInvalid CVC code
INCORRECT_EXPIRYInvalid expiration date
INCORRECT_PINInvalid PIN
EXPIRED_CARDThe card has expired
CALL_ISSUERThe cardholder should contact their issuer
PICK_UP_CARDThe card cannot be used
LOST_CARDThe card has been reported lost
STOLEN_CARDThe card has been reported stolen
FRAUDULENTThe card has been flagged as fraudulent
GENERIC_DECLINEA generic decline with no additional detail

Payment error structure

{
  "code": "PAYMENT_METHOD_PROVIDER_DECLINE",
  "decline_code": "INSUFFICIENT_FUNDS",
  "message": "The card has insufficient funds.",
  "payment_method": "accounts/acct_YOUR_ACCOUNT/payment-methods/pm_PAYMENT_METHOD_ID"
}