Errors and utilities

Retries

The client retries a failed attempt while its RetryPolicy allows:

FieldTypeDefaultDescription
maxRetriesnumber2Retries after the first attempt. 0 turns retries off.
backoffInitialMsnumber500The first wait, doubled for each retry up to backoffMaxMs.
backoffMaxMsnumber5000The longest backoff wait.
backoffJitternumber0.25The fraction of each backoff wait taken off at random, from 0 to 1.
httpStatusesReadonlySet<number>408, 429 and 500 to 599Statuses to retry. A set you pass replaces this one. An error whose body says "retryable": false is never retried.
respectRetryAfterbooleantrueWait what retry-after-ms or retry-after asks, instead of the backoff.
maxRetryAfterMsnumber60000The longest server delay to honor. A longer one falls back to the backoff.
apiConnectionErrorbooleantrueRetry an APIConnectionError.
apiTimeoutErrorbooleantrueRetry an APITimeoutError.
timeoutMsnumber | null30000The 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 APITimeoutError and a 529 that Drex sends after waiting 55 seconds for the model.
  • A retry-after that 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.