Skip to content
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

retry-axios doesn't work with latest axios release v1.1.3 #205

Open
neillfontes-klar opened this issue Nov 7, 2022 · 4 comments
Open

retry-axios doesn't work with latest axios release v1.1.3 #205

neillfontes-klar opened this issue Nov 7, 2022 · 4 comments

Comments

@neillfontes-klar
Copy link

neillfontes-klar commented Nov 7, 2022

I have a project that uses retry-axios with axios v0.27.2. It has been upgraded to axios v1.1.3 and the retries simply stopped working - it looks to me that the retries are somehow cached and the response is not being updated from the server. Downgrading to the previous v0.27.2 release solved the problem.

This is roughly how the code is structured:

import axios from 'axios'
import * as axiosRetry from 'retry-axios'

...

const retryConfig = {
  retry: 10,
  retryDelay: 2500,
  httpMethodsToRetry: ['PATCH'],
  statusCodesToRetry: [[404, 415]],
  onRetryAttempt: (err) => {
    const cfg = axiosRetry.getConfig(err)
    helper.log(`retry update transaction date #${cfg.currentRetryAttempt}...`)
  }
}
axiosRetry.attach()

...

patch(data) {
    const options = {
      method: 'patch',
      raxConfig: retryConfig,
      url: `theUrl`,
      headers: {
        'Content-Type': 'application/json'
      },
      data
    }
    return axios(options)
  }

Possibly relates to #201

@mayrsascha
Copy link

Same issue here

@JustinBeckwith It would be nice to know if/when you are planning to fix this and/or if you have any hints for us of what this bug could be.

@JustinBeckwith
Copy link
Owner

👋 no plan at the moment to fix this, but happy to review pull requests

@hisham
Copy link

hisham commented Mar 2, 2023

+1

@sschmeck
Copy link

sschmeck commented Jul 26, 2023

Seems known Axios bug, see axios/axios#5089.

The following line could fix the problem, which needs to placed before retrying the request.

//TODO: To be removed when https://github.com/axios/axios/issues/5089 gets closed.
err.config!.headers = JSON.parse(JSON.stringify(err.config?.headers || {}))

As client/user of retry-axios, you could extend your onRetryAttempt callback of your concrete RetryConfig.

const retryConfig: RetryConfig = {
  retry: 3,
  retryDelay: 1000,
  httpMethodsToRetry: ['GET'],
  statusCodesToRetry: [[404,500]],
  onRetryAttempt: err => {
    //TODO: To be removed when https://github.com/axios/axios/issues/5089 gets closed.
    err.config!.headers = JSON.parse(JSON.stringify(err.config?.headers || {}))
  }
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants