Skip to main content
Every request throws a typed error you can discriminate with instanceof. All extend UnitPayError.

Usage

import { HttpError, NetworkError, TimeoutError } from '@unitpay/react';

try {
  await client.get('/customers/cus_123');
} catch (e) {
  if (e instanceof HttpError && e.isAuthError) {
    // 401 / 403 — redirect to sign-in
  } else if (e instanceof HttpError && e.isRateLimited) {
    // 429 — back off (the client already honors Retry-After)
  } else if (e instanceof TimeoutError) {
    // exceeded the configured timeout
  } else if (e instanceof NetworkError) {
    // offline / DNS / TLS
  }
}

Error types

HttpError

A non-2xx response. Carries status, code, requestId, and details, plus convenience getters:
isAuthError
boolean
true for 401 / 403.
isRateLimited
boolean
true for 429.
isRetryable
boolean
true for 408 / 429 / 5xx. The client retries these automatically with jittered exponential backoff.

NetworkError

A failed fetch — offline, DNS, or TLS error. Carries the underlying cause.

TimeoutError

The request exceeded the configured timeout.

PmInUseError

Thrown by usePaymentMethods().detach() when the card is still in use. Carries activeSubscriptionIds and autoTopupAccountIds so you can tell the customer what’s blocking removal — pair it with usePaymentMethodDependencies to show the blockers before they try.
Transient failures (408 / 429 / 5xx and network errors) are retried automatically with jittered exponential backoff. Retry budget and per-request timeout are configurable on the client.