BchainPayBchainPay

Errors

The BchainPay API uses conventional HTTP status codes and returns a consistent JSON error envelope. Always branch on code, not message — messages are human-readable and may change without notice.

Error envelope

Every error response wraps the details inside an error object:

{
  "error": {
    "code": "invalid_request",
    "message": "The request body is invalid",
    "details": { "field": "reason" },
    "request_id": "req_8H2xK91"
  }
}
FieldTypeRequiredDescription
codestringrequiredStable machine-readable error code. Always switch on this value.
messagestringrequiredHuman-readable explanation. Safe to log but not to display to end users.
detailsobjectoptionalAdditional context when available. Typically maps a field name to the reason it failed validation.
request_idstringrequiredUnique identifier for this request. Include it in support tickets to speed up triage.

HTTP status codes

StatusMeaning
200OK.
201Resource created.
400Bad request — invalid or missing parameters.
401Authentication failed.
403Authenticated but insufficient permissions.
404Resource does not exist.
409Conflict — idempotency key reuse or invalid state transition.
422Semantically invalid — e.g. unsupported currency.
429Rate limited. Retry with exponential backoff.
500Internal server error. Retry with backoff.
503Service temporarily unavailable. Retry with backoff.

Error codes

CodeHTTP StatusMessage
invalid_request400The request body is invalid
missing_idempotency_key400Idempotency-Key header is required
unauthorized401Invalid or missing API key
forbidden403Insufficient permissions
not_found404Resource not found
conflict409Resource already exists with different parameters
invalid_state_transition409This action is not allowed in the current state
invalid_currency422Currency not supported
rate_limited429Too many requests
internal_error500An internal error occurred
price_unavailable503Token price is currently unavailable; please retry shortly
no_wallets_available503No wallets available for the requested network

Handling errors

const res = await fetch("https://api.bchainpay.com/v1/payment-intents", {
  method: "POST",
  headers: { /* ... */ },
  body: JSON.stringify(payload),
});
 
if (!res.ok) {
  const { error } = await res.json();
 
  switch (error.code) {
    case "rate_limited":
      // back off and retry
      break;
    case "price_unavailable":
    case "no_wallets_available":
      // transient — retry with backoff
      break;
    case "invalid_request":
      // inspect error.details for field-level info
      console.error(error.details);
      break;
    default:
      console.error(`[${error.code}] ${error.message} (${error.request_id})`);
  }
}
Last updated Edit on GitHub