Errors and utilities
Retries
The client retries a failed attempt while its RetryPolicy allows:
| Field | Type | Default | Description |
|---|---|---|---|
maxRetries | number | 2 | Retries after the first attempt. 0 turns retries off. |
backoffInitialMs | number | 500 | The first wait, doubled for each retry up to backoffMaxMs. |
backoffMaxMs | number | 5000 | The longest backoff wait. |
backoffJitter | number | 0.25 | The fraction of each backoff wait taken off at random, from 0 to 1. |
httpStatuses | ReadonlySet<number> | 408, 429 and 500 to 599 | Statuses to retry. A set you pass replaces this one. An error whose body says "retryable": false is never retried. |
respectRetryAfter | boolean | true | Wait what retry-after-ms or retry-after asks, instead of the backoff. |
maxRetryAfterMs | number | 60000 | The longest server delay to honor. A longer one falls back to the backoff. |
apiConnectionError | boolean | true | Retry an APIConnectionError. |
apiTimeoutError | boolean | true | Retry an APITimeoutError. |
timeoutMs | number | null | 30000 | The retry budget: no retry starts once the time since the call began, plus the next wait, would reach it. It doesn't cut a running attempt short. null removes it. |
A value out of range throws a NaceError. A retry you pass to the client or to one call is merged over the policy beneath it, so name only the fields you change.
The budget. Before each retry, the client adds the time since the call started to the next wait. If that reaches timeoutMs, it stops and throws the last error. With the defaults, a 60-second attempt timeout and a 30-second budget:
- An attempt that fails after 30 seconds or more is never retried. That covers every
APITimeoutErrorand a529that Drex sends after waiting 55 seconds for the model. - A
retry-afterthat doesn't fit in what is left of the 30 seconds isn't waited out, such as the 30 seconds a paused API asks for.
To retry those, give the budget room for every attempt and wait, or remove it:
// Three 60 s attempts and two waits of up to 60 s.
const client = new NaceClient({ retry: { timeoutMs: 300_000 } });
// Or no budget at all: maxRetries alone limits the call.
const patient = new NaceClient({ retry: { timeoutMs: null } });A retry of a request to Drex carries X-Nace-Retry-Count. Document creates carry an Idempotency-Key, minted once per call, so their retries never start or bill a second job. extractionSchemas.create and createVersion aren't retried unless you pass retry, and jobs.events is never retried.