Retry Logic Implementation
Implement exponential backoff with jitter for handling transient errors.
GET
/v2/errors/retry-logic-implementationRequires authenticationCode Example
typescript
async function withRetry<T>(
fn: () => Promise<T>,
maxRetries = 3
): Promise<T> {
for (let attempt = 0; attempt <= maxRetries; attempt++) {
try {
return await fn()
} catch (error: any) {
if (attempt === maxRetries) throw error
// Only retry on 5xx or network errors
const status = error?.response?.status
if (status && status < 500) throw error
// Exponential backoff with jitter
const baseDelay = Math.pow(2, attempt) * 1000
const jitter = Math.random() * 1000
await new Promise(r => setTimeout(r, baseDelay + jitter))
}
}
throw new Error('Unreachable')
}
// Usage
const data = await withRetry(() =>
client.resources.list({ limit: 100 })
)Last updated: April 21, 2026typescript