@nuskin/axios-util
axios-util
allows you to use Axios in the exact same way you would use Axios
by itself. By default axios-util
will set the timeout to 10000ms.
Retry has been implemented with the axios-retry module.
Use getRetryAxiosInstance()
to get an axios instance with retry
added to it. All defaults of
axios-retry
are used except for retryDelay. retryDelay is set to axiosRetry.exponentialDelay.
You can set your own behavior by providing an axios-retry
options object to getRetryAxiosInstance()
.
Installing
Usng npm:
npm install @nuskin/axios-util
Usng yarn:
yarn add @nuskin/axios-util
Example usage
const { axios } = require('@nuskin/axios-util')
Customizing retry
You can customize your retry logic by accessing axios-retry
.
const { getRetryAxiosInstance } = require('@nuskin/axios-util')
let retryDelay = process.env.AXIOS_RETRY_DELAY || 5000
const myAxiosWithRetry = getRetryAxiosInstance({
retries: 3,
shouldResetTimeout: true,
retryDelay: (retryCount) => {
return retryCount * retryDelay
},
retryCondition: (error) => {
return error.response?.status >= 500 || error.code === 'ECONNABORTED'
},
onRetry: (retryCount, error, requestConfig) => {
log.info(
{
retryCount,
message: error.message,
statusCode: error.response?.status,
statusText: error.response?.statusText,
responseData: error.response?.data
},
requestConfig.metric
)
return true
}
})
Other possibilities for axios-util
Resources
License
MIT