cimplify

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

StatusMeaningRetryable
400Validation errorNo
401Authentication requiredNo
403Forbidden (insufficient scope)No
404Resource not foundNo
409Conflict (duplicate resource)No
422Business logic violationNo
429Rate limitedYes (after delay)
500Server errorYes

Common error codes

Auth

CodeDescription
UNAUTHORIZEDMissing, invalid, or expired API key/token
FORBIDDENKey lacks permission for this resource
AUTH_INCOMPLETEAuthElement hasn't completed authentication
AUTH_LOSTSession cleared during checkout

Cart

CodeDescription
CART_NOT_FOUNDCart could not be resolved
CART_EXPIREDCart is no longer active
ITEM_UNAVAILABLERequested item is unavailable
VARIANT_OUT_OF_STOCKSelected variant has no stock

Checkout

CodeDescription
ALREADY_PROCESSINGCheckout is already in progress
PAYMENT_FAILEDPayment provider rejected the charge
TIMEOUTRequest exceeded timeout
NO_PAYMENT_ELEMENTPaymentElement required but not mounted

Catalogue

CodeDescription
NOT_FOUNDProduct or resource not found
OUT_OF_STOCKInventory depleted for requested item
QUOTE_EXPIREDPricing quote has expired

General

CodeDescription
VALIDATION_ERROROne or more input fields are invalid
NETWORK_ERRORNetwork connectivity failure
UNKNOWN_ERRORUnexpected 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.

Related