Errors

A failed request returns an error object, and its type determines how to handle it. The HTTP status is 4xx when the request can’t be completed, such as a missing parameter or a declined card, and 5xx when the error is on Bias’s side.

Invalid request errors that an integration can handle have a code. Payment errors have a decline_code, listed in decline codes.

An error’s message is written for developers. customer_message is safe to show to the customer, such as for a card decline or an expired discount code, and is null when Bias has no customer wording for the error.

The request-id response header identifies the request. Include it when you contact support.

The Error object

The request can't be processed as sent, such as when a parameter is missing or invalid, or the object's current state doesn't allow the action. param names the parameter at fault.

Name
object
Type
"error",
Description
The object's type.
Name
error
Type
object,
Description
Details about the error.
Properties
Name
type
Type
"invalid_request_error",
Name
live
Type
boolean or null,
Description
true for a live request, false for a sandbox request, or null if the request wasn't authenticated as a merchant.
Name
code
Type
enum or null,
Description
A code for errors an integration can handle.
Properties
Name
message
Type
string,
Description
A message about the error, written for developers.
Name
customer_message
Type
string or null,
Description
A message about the error that's safe to show to the customer.
Name
param
Type
string or null,
Description
The request parameter the error relates to.

or

Handling errors

  • Retry a rate_limit_error after the number of seconds in its Retry-After header.
  • Retry a server_error with exponential backoff.
  • For a payment_error, the decline code says whether to retry or ask the customer for another payment method.

An idempotency key makes it safe to retry a request after a network failure.

Errors in the SDKs

The Python SDK raises a typed exception for each error type, and the Rust SDK returns Err(biaspay::Error::Api(_)).

The TypeScript SDK returns API errors as values, typed as a union with the successful response. Only network and other fetch errors are thrown.

Warning

Check whether a response is an error object (res.object === "error") before using its properties.
const customer = await bias.customers.create();
customer satisfies Customer | InvalidRequestError | IdempotencyError | RateLimitError | ServerError;

if (customer.object === "error") {
    throw new Error(customer.error.message);
}