axios-retry-after
A tiny HTTP retry interceptor for axios.
This interceptor catches HTTP 429 errors, reads the Retry-After
header, and retries the request at the proper type.
Installation
With NPM:
npm install --save axios-retry-after
With Yarn:
yarn add axios-retry-after
Example usage
import axios from 'axios'
import retry from 'axios-retry-after'
const client = axios.createClient()
client.interceptors.response.use(null, retry(client))
Customizing retry behavior
You can optionally customize the behavior of this interceptor by passing a second argument including one or more of the methods demonstrated below:
client.interceptors.response.use(null, retry(client, {
isRetryable (error) {
return (
error.response && error.response.status === 429 &&
error.response.headers['x-retry-after'] && error.response.headers['x-retry-after'] <= 60
)
}
wait (error) {
return new Promise(
resolve => setTimeout(resolve, error.response.headers['x-retry-after'])
)
}
retry (axios, error) {
if (!error.config) {
throw error
}
return axios(error.config)
}
}))