Skip to main content
A request that gets a non-2xx response throws NozleApiError. It carries status, code, errorDetails, requestId, retryAfter and hasCode(). Any other failure is a plain Error: a network error, a timeout, or a local check that fails before a request is sent. Before 0.13.0, only checkout(), checkoutInvoice(), verifyCheckout(), checkoutStatus() and the nozle.margin.* queries threw it (from 0.10.0). Every other call threw a plain Error with the status only in its message.

Branch on NozleApiError

The message keeps the <operation> failed: <status> <status text> form, and the class extends Error.

Branch on the status

error.status works on every call. Use status to separate a retryable failure from one that is not:

Retry behavior

By default the SDK does not retry: every call is one request with a per-attempt timeout (timeout, default 10 seconds). Set maxRetries to retry network errors, timeouts, 429 and 5xx with backoff, or after NozleApiError.retryAfter seconds when the service sent Retry-After:
Only requests that are safe to repeat are retried: reads, calls that carry an idempotency key (such as usage.track), event, cost event and customer writes, and the read-only usage check and transition preview. subscribe, checkout and other writes without a key are never retried. To retry in your own code instead:
  • Retry only after a network error, a 429, or a 5xx.
  • Retry with the same idempotency key and the same request, including the timestamp.
  • For track(), retry the same event with the same transactionId and timestamp.
  • Do not generate a new idempotency key after an uncertain outcome.

Idempotency

usage.track() needs an idempotencyKey. A retry with an identical request returns the original result, including a denial, and does not charge again. The same key with a different request returns 409. If you omit timestamp, the SDK fills in the current time once per idempotency key and reuses it for a retry on the same client. Pass a fixed timestamp for a retry from another process or after a restart. See product credits and usage tracking.