Skip to content

retry

retry(config?): Policy

Defined in: src/policies/resilience/retry.ts:85

Retry failed upstream calls with configurable backoff.

After next() completes, checks the response status against retryOn codes. If a retry is warranted and a _proxyRequest is available on the context (set by createUrlUpstream() in gateway.ts), the policy clones the stored request and calls fetch() directly — fully concurrency-safe with no globalThis.fetch patching.

For handler-based or service-binding upstreams (no _proxyRequest), the retry policy is a no-op since there is no stored request to re-issue. Sets X-Retry-Count on the response when retries occur.

RetryConfig

Retry limits, backoff strategy, and retryable status codes.

Policy

A Policy at priority 90 (runs late, wraps the upstream fetch).

// Retry 502/503/504 up to 3 times with exponential backoff
retry();
// Fixed 500ms delay, retry on 500 too
retry({
maxRetries: 2,
retryOn: [500, 502, 503, 504],
backoff: "fixed",
baseDelayMs: 500,
});