feat(fetcher): retry all 4xx requests too
This commit is contained in:
parent
956ba68550
commit
728bc7ecba
1 changed files with 7 additions and 3 deletions
10
src/index.ts
10
src/index.ts
|
|
@ -1,6 +1,6 @@
|
|||
import express, { NextFunction, Request, Response } from 'express';
|
||||
import axios from 'axios';
|
||||
import axiosRetry from 'axios-retry';
|
||||
import axios, { AxiosError } from 'axios';
|
||||
import axiosRetry, { isNetworkOrIdempotentRequestError } from 'axios-retry';
|
||||
import { setupCache } from 'axios-cache-interceptor';
|
||||
import winston from 'winston';
|
||||
import {
|
||||
|
|
@ -30,7 +30,11 @@ const logger = winston.createLogger({
|
|||
});
|
||||
|
||||
setupCache(axios);
|
||||
axiosRetry(axios, { retries: 3, retryDelay: axiosRetry.exponentialDelay });
|
||||
axiosRetry(axios, {
|
||||
retries: 3,
|
||||
retryDelay: axiosRetry.exponentialDelay,
|
||||
retryCondition: (error: AxiosError) => isNetworkOrIdempotentRequestError(error) || (error.response?.status ?? 0) > 400,
|
||||
});
|
||||
|
||||
const fetcher = new Fetcher(axios, logger);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue