softonic / axios-retry

Axios plugin that intercepts failed requests and retries them whenever possible
Other
1.9k stars 167 forks source link

Retry for 429 only #105

Closed iDVB closed 4 years ago

iDVB commented 4 years ago

Is there a way to retry with backoff for 429 only?

shaharsol commented 4 years ago
retryCondition: e => e.code === 429,
retryDelay: axiosRetry.exponentialBackoff
bennycode commented 4 years ago

I recommend the following (in order to keep the default behaviour):

import axiosRetry, {isNetworkOrIdempotentRequestError} from 'axios-retry';

// ... 

retryCondition: (error: AxiosError) => {
  return isNetworkOrIdempotentRequestError(error) || error.code === 429;
},
ndberg commented 4 years ago

I don't have an error.code, but if I have a response from the I have a error.response.status.

I got mine working like this: axiosRetry(axiosInstance, { retries: 5, retryCondition: e => { return isNetworkOrIdempotentRequestError(e) || e.response.status === 429 }, retryDelay: axiosRetry.exponentialDelay });