Import
What it does
RetryPolicy wraps any async function with automatic retries using exponential backoff and jitter. When all attempts are exhausted, the last error is thrown. A configurable shouldRetry predicate controls which errors trigger retries.
ApiClient creates an internal RetryPolicy from the retryPolicy config option. Use this class directly when you need retries outside of HTTP requests.Constructor
RetryConfig
The built-in
shouldRetry predicate retries on:
- HTTP status
408(timeout),429(rate limit), and5xx(server errors) - Network-related error messages (
timeout,network,ECONNREFUSED,ECONNRESET)
Methods
execute<T>(fn)
fn up to maxAttempts times. Returns the result on the first success. Throws the last error if all attempts fail.