Skip to content

Errors & reliability

The SDK is built for a payments flow, so it handles transient failures safely and gives you precise errors to act on.

Retries

Transient failures are retried automatically with exponential backoff and jitter:

  • Network errors and timeouts
  • 429 Too Many Requests (honors the Retry-After header)
  • 5xx server errors

Only safe requests retry: reads (GET), and mutations that carry an idempotency key. Default is 2 retries; configure with maxRetries.

new ShoppableCheckout({ token: "pk_test_...", maxRetries: 3, timeout: 15000 });

Idempotency

Every mutating call (prepareCheckout, updateCheckout, and the createIntent and completeCheckout steps of placeOrder) sends an auto-generated Idempotency-Key, so an automatic retry can never create a duplicate order or charge. Pass your own key to make a retry idempotent across separate invocations (for example a user-triggered retry):

await client.prepareCheckout(request, { idempotencyKey: myStableKey });

Timeouts and cancellation

Each request times out after timeout ms (default 30000) and accepts an AbortSignal:

const controller = new AbortController();
const promise = client.lookupProducts(upcs, {}, { signal: controller.signal });
controller.abort(); // rejects with an AbortError, never retried

Error types

Failures from the API throw a subclass of ShoppableApiError. Catch the base to handle all of them, or a subclass for finer control. Every API error carries status, the encrypted support ref (when present), the server requestId, and the raw response body.

ErrorWhen
ShoppableAuthError401: the session token is missing, invalid or expired and could not be refreshed.
ShoppableValidationError400 / 422: the request was rejected, for example an item is out of stock. See below.
ShoppableNotFoundError404: see Checkout not found.
ShoppableRateLimitError429 (has retryAfter in ms).
ShoppableServerError5xx.
ShoppableNetworkErrorNo response (offline, DNS, TLS).
ShoppableTimeoutErrorExceeded the timeout.
ShoppableApiErrorAny other status, such as the 403 from getCartConfiguration when your site is not allowed for the token. See Get your keys.

Two errors are not API errors and do not extend ShoppableApiError:

ErrorWhen
ShoppablePaymentErrorplaceOrder only: Stripe did not confirm the payment (declined card, failed 3-D Secure, closed wallet). No order was placed and nothing was charged. message is Stripe’s shopper-facing text; code is Stripe’s error code.
ShoppableConfigErrorThe SDK is misconfigured, for example no token, or no origin in Node.
import {
ShoppableApiError,
ShoppablePaymentError,
ShoppableRateLimitError,
} from "@shoppable/checkout";
try {
await client.placeOrder(checkoutId, { confirmPayment });
} catch (err) {
if (err instanceof ShoppablePaymentError) {
showError(err.message); // let the shopper try another card
} else if (err instanceof ShoppableRateLimitError) {
// back off and retry later
} else if (err instanceof ShoppableApiError) {
showError("We couldn't complete your order and your card was not charged.", err.ref);
}
}

Payments covers what to show the shopper when an order fails.

Validation messages

Some checks answer with a plain-text body rather than JSON, for example “Trail Jacket gone out of stock” or “Minimum order amount for Acme is $25”. The SDK uses that text as the error’s message, so it is readable as is. When prepareCheckout fails because of specific cart lines, the JSON body also lists them in errors; see When pricing fails.

Checkout not found

ShoppableNotFoundError with the message “Checkout not found” means the checkout id does not exist or belongs to a different Shoppable account than your token, for example an id saved in the browser while testing with another token. It can come from updateCheckout, placeOrder, and prepareCheckout with _id. Drop the stored id and start a new checkout without _id.