Error Handling

Every backend call throws a typed ChromeShipError. Branch on error.code instead of parsing strings.

Error codes

CodeHTTPWhat to do
auth_requiredNo session at all. Thrown manually — never from HTTP status. Show login.
auth_expired401Server returned 401 — token expired. Re-authenticate.
entitlement_required402User needs to pay. Send to checkout.
forbidden403Insufficient permissions.
bad_request400 / 422Invalid input. Check the payload.
rate_limited429Too many requests. Back off.
server_error500+Server-side failure. Retry or contact support.
network_errorFetch failed. Check connection, retry.
unknownUnexpected. Report the error.

Usage

import { ChromeShipError } from "@/integrations/shared";

try {
  await billing.requireAccess("pro");
} catch (error) {
  if (error instanceof ChromeShipError) {
    switch (error.code) {
      case "entitlement_required":
        await billing.checkout({ mode: "payment", priceId: "price_xxx" });
        break;
      case "auth_expired":
        // Show re-authentication UI
        break;
      case "network_error":
        // Show offline state, allow retry
        break;
    }
  }
}