-
Notifications
You must be signed in to change notification settings - Fork 165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add callback option when it retries #25
Comments
I'm working on an existing code based that has axios-retry implemented and it is hard to debug. It is difficult to identify if it is retrying. A callback would be helpful. |
I think you could use a different interceptor to detect retries. You just need to register it after axios-retry and check the retry count. We're trying to keep the API minimal, and this use case can be implemented without adding new options. |
If anyone else ends up here trying to answer this question, here's an implementation based on the suggestion to use interceptors. The example is in TypeScript but it will be the same in JS, just remove the types. This gets the count of the tries and logs a warning: interface AxiosRetryRequestConfig extends AxiosRequestConfig {
'axios-retry'?: {
retryCount: number,
lastRequestTime: number
}
}
axios.interceptors.request.use((config: AxiosRequestConfig) => {
const retryRequestData = (<AxiosRetryRequestConfig>config)['axios-retry']
if (retryRequestData) {
const retryCount = retryRequestData.retryCount
logger.warn(`[webhook] Webhook call retry #${retryCount}: ${config.url}`)
}
return config
}) My logger output:
|
It would be useful to have a callback function whenever
axios
retries, for example to update UI status.The text was updated successfully, but these errors were encountered: