Error Handling
All SDK methods return Result<T, CimplifyError> and never throw. Check result.ok first.
Result pattern
const result = await client.catalogue.getProducts();
if (!result.ok) {
console.log(result.error.code); // "UNAUTHORIZED"
console.log(result.error.message); // "Authentication is missing..."
console.log(result.error.retryable); // true | false
console.log(result.error.suggestion); // "Ensure a valid access token..."
console.log(result.error.docs_url); // "https://docs.cimplify.io/reference/error-codes#unauthorized"
return;
}
const products = result.value;CimplifyError
TYPESCRIPT
class CimplifyError extends Error {
code: string; // e.g. "CART_NOT_FOUND"
message: string; // Human-readable description
retryable: boolean; // Safe to retry automatically?
suggestion?: string; // Developer-facing fix suggestion
docs_url?: string; // Link to error code reference
}HTTP status codes
| Status | Meaning | Retryable |
|---|---|---|
400 | Validation error | No |
401 | Authentication required | No |
403 | Forbidden (insufficient scope) | No |
404 | Resource not found | No |
409 | Conflict (duplicate resource) | No |
422 | Business logic violation | No |
429 | Rate limited | Yes (after delay) |
500 | Server error | Yes |
Common error codes
Auth
| Code | Description |
|---|---|
UNAUTHORIZED | Missing, invalid, or expired API key/token |
FORBIDDEN | Key lacks permission for this resource |
AUTH_INCOMPLETE | AuthElement hasn't completed authentication |
AUTH_LOST | Session cleared during checkout |
Cart
| Code | Description |
|---|---|
CART_NOT_FOUND | Cart could not be resolved |
CART_EXPIRED | Cart is no longer active |
ITEM_UNAVAILABLE | Requested item is unavailable |
VARIANT_OUT_OF_STOCK | Selected variant has no stock |
Checkout
| Code | Description |
|---|---|
ALREADY_PROCESSING | Checkout is already in progress |
PAYMENT_FAILED | Payment provider rejected the charge |
TIMEOUT | Request exceeded timeout |
NO_PAYMENT_ELEMENT | PaymentElement required but not mounted |
Catalogue
| Code | Description |
|---|---|
NOT_FOUND | Product or resource not found |
OUT_OF_STOCK | Inventory depleted for requested item |
QUOTE_EXPIRED | Pricing quote has expired |
General
| Code | Description |
|---|---|
VALIDATION_ERROR | One or more input fields are invalid |
NETWORK_ERROR | Network connectivity failure |
UNKNOWN_ERROR | Unexpected error |
Retry strategy
Retry when error.retryable === true. Use exponential backoff, max 3 retries. The SDK client handles this automatically for server errors and network failures.
TYPESCRIPT
import { ErrorCode } from "@cimplify/sdk";
const result = await client.cart.addItem({ item_id: "prod_123", quantity: 1 });
if (!result.ok) {
if (result.error.retryable) {
// Safe to retry with backoff
showToast("Connection issue. Retrying...");
} else {
// Show error, don't retry
switch (result.error.code) {
case ErrorCode.ITEM_UNAVAILABLE:
showToast("This item is no longer available");
break;
case ErrorCode.OUT_OF_STOCK:
showToast("This item is out of stock");
break;
default:
showToast(result.error.message);
}
}
}For the full list of error codes, see the Error Codes Reference.