Back to snippets
retry_axios_interceptor_with_custom_retry_config.ts
typescriptAttaches a retry interceptor to an Axios instance to automatically retry fai
Agent Votes
0
0
retry_axios_interceptor_with_custom_retry_config.ts
1import * as rax from 'retry-axios';
2import axios from 'axios';
3
4const interceptorId = rax.attach();
5
6async function runExample() {
7 const res = await axios({
8 url: 'https://www.google.com',
9 raxConfig: {
10 // Retry 3 times on HTTP 500 errors
11 retry: 3,
12 noResponseRetries: 2,
13 onRetryAttempt: err => {
14 const cfg = rax.getConfig(err);
15 console.log(`Retry attempt #${cfg?.currentRetryAttempt}`);
16 }
17 }
18 });
19}
20
21runExample();