An Axios utility ...
axios-util enables you to utilize Axios as you normally would. By default, axios-util sets
the timeout to _10000ms_.
Retry functionality is implemented using the axios-retry module. Utilize getRetryAxiosInstance() to obtain an Axios instance with retry capabilities. All default settings of axios-retry are applied, except for the retryDelay, which is set to axiosRetry.exponentialDelay. You can customize the retry behavior by supplying an axios-retry options object to getRetryAxiosInstance().
Using npm:
``bash`
npm install @nuskin/axios-util
Using yarn:
`bash`
yarn add @nuskin/axios-util
For ESM syntax, use import:`js`
import { axios, getRetryAxiosInstance } from '@nuskin/axios-util'
For CommonJS, use require:`js`
const { axios, getRetryAxiosInstance } = require('@nuskin/axios-util')
To customize the retry logic, access axios-retry with ESM import syntax:
`js``
let retryDelay = process.env.AXIOS_RETRY_DELAY || 5000
const myAxiosWithRetry = getRetryAxiosInstance({
retries: 3,
shouldResetTimeout: true,
retryDelay: (retryCount) => {
return retryCount * retryDelay
},
retryCondition: (error) => {
// If retry condition is not specified, by default, idempotent requests are retried
return error.response?.status >= 500 || error.code === 'ECONNABORTED'
},
onRetry: (retryCount, error, requestConfig) => {
console.log(
{
retryCount,
message: error.message,
statusCode: error.response?.status,
statusText: error.response?.statusText,
responseData: error.response?.data
},
requestConfig.metric
)
return true;
}
})