Skip to content

Function: withRetry()

ts
function withRetry<T>(operation, options?): Promise<T>;

Defined in: src/core/withRetry.ts:38

Stable

Wraps an async operation with automatic retry on failures worth retrying.

Retries a transient transport failure and a 502/503/504 gateway error — the same policy the client applies to its own requests, so wrapping a call does not change which failures count as temporary. Everything else is rethrown on the first attempt: 401, 403, 404 and 500 describe the request, not the moment. A 429 joins the list only under retryRateLimit, and then honours Retry-After.

It is therefore a transient-failure helper, not a poller — to wait on eventually-consistent state, loop on the value rather than on a thrown error.

Type Parameters

Type Parameter
T

Parameters

ParameterType
operation() => Promise&lt;T>
optionsRetryOptions

Returns

Promise&lt;T>

Example

typescript
  const page = await withRetry(
    () => confluence.page.getPageById({ id: 12345 }),
    { maxAttempts: 4, initialDelayMs: 500 },
  );
  ```;