retry-axios icon indicating copy to clipboard operation
retry-axios copied to clipboard

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

Open neillfontes-klar opened this issue 2 years ago • 4 comments

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 https://github.com/JustinBeckwith/retry-axios/pull/201

neillfontes-klar avatar Nov 07 '22 10:11 neillfontes-klar

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.

mayrsascha avatar Dec 07 '22 06:12 mayrsascha

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

JustinBeckwith avatar Dec 07 '22 18:12 JustinBeckwith

+1

hisham avatar Mar 02 '23 21:03 hisham

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 || {}))
  }
};

sschmeck avatar Jul 26 '23 15:07 sschmeck