Configuration for retry behavior when requests fail
Controls how failed requests should be retried with exponential backoff
// Simple retry with default settingsconst simpleRetry: RetryConfig = { maxRetries: 3 };// Advanced retry configurationconst advancedRetry: RetryConfig = { maxRetries: 5, delay: 2000, shouldRetry: [408, 429, 500, 502, 503, 504]};// Custom retry logicconst customRetry: RetryConfig = { maxRetries: 3, shouldRetry: (error) => error instanceof Error && error.name === 'NetworkError'}; Copy
// Simple retry with default settingsconst simpleRetry: RetryConfig = { maxRetries: 3 };// Advanced retry configurationconst advancedRetry: RetryConfig = { maxRetries: 5, delay: 2000, shouldRetry: [408, 429, 500, 502, 503, 504]};// Custom retry logicconst customRetry: RetryConfig = { maxRetries: 3, shouldRetry: (error) => error instanceof Error && error.name === 'NetworkError'};
Maximum number of retry attempts before giving up
3 // Will try original request + 3 retries = 4 total attempts Copy
3 // Will try original request + 3 retries = 4 total attempts
Optional
Base delay between retries in milliseconds (default: 1000)
Uses exponential backoff: delay * 2^attempt + jitter
1000 // First retry after 1s, second after ~2s, third after ~4s Copy
1000 // First retry after 1s, second after ~2s, third after ~4s
HTTP status codes to retry on, or custom retry function
Array of status codes or function to determine if request should be retried
[408, 429, 500, 502, 503, 504] // Retry on timeout and server errors Copy
[408, 429, 500, 502, 503, 504] // Retry on timeout and server errors
(error) => error.status >= 500 // Retry only on server errors Copy
(error) => error.status >= 500 // Retry only on server errors
Configuration for retry behavior when requests fail
Description
Controls how failed requests should be retried with exponential backoff
Example