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

axios-retry problem with baseURL #114

Closed
simllll opened this issue Mar 5, 2018 · 6 comments
Closed

axios-retry problem with baseURL #114

simllll opened this issue Mar 5, 2018 · 6 comments
Labels

Comments

@simllll
Copy link
Contributor

simllll commented Mar 5, 2018

When a request fails, a 2nd retry (with axios-retry) fails due to the reason that the baseURL gets attached again.

e.g. first request (browserBaseURL is "/api")
/api/test fails
axios retries: /api/api/test
2nd retry: /api/api/api/test

How to test: just make a test with a failing endpoint and set browserBaseURL to '/api'.

regards
Simon

This bug report is available on Nuxt.js community (#c99)
@pi0 pi0 added the bug label Mar 6, 2018
@pi0 pi0 changed the title axios retry adds "baseURL" again if browserBaseURL is set. axios-retry problem with baseURL Mar 6, 2018
@ricosmall
Copy link
Contributor

Is this bug fixed yet?

@simllll
Copy link
Contributor Author

simllll commented Oct 24, 2018

No, but you can overcome it by not providing a Baseurl and just provide the whole path to the request itself.

@Spyna
Copy link

Spyna commented Apr 4, 2019

Facing the same issue, and is not related to retry-axios but to axios.
If you look at dispatchRequest.js in the axios source code you'll see near line 25.

  // Support baseURL config
  if (config.baseURL && !isAbsoluteURL(config.url)) {
    config.url = combineURLs(config.baseURL, config.url);
  }

If you don't use an absolute URL as baseURL, the config.url will be always combined with the baseURL.

This means that..
if you do window.axios.defaults.baseURL = '/v1/api/', the first time you execute a request, such as axios.get('/user') the actual url will be [config.baseURL] + [config.url] = '/v1/api/ + user' = '/v1/api/user'.

When that request is retried the code of dispatchRequest.js will be repeated, and now the value of url is already "prepended" with the baseURL. So the config.url will end up with [baseURL] + [url] = '/v1/api/ + /vi/api/user' = '/v1/api/v1/api/user'.

Solutions

  • Use an absolute URL as the baseURL
  • Use a request interceptor to purge the config.URL if the request is being retried

@usb248
Copy link

usb248 commented Jun 21, 2019

Other bug in 0.19.0 : bug
Personnaly, i use axios retry and i can't use 0.19 branch because of this ....

@pi0
Copy link
Member

pi0 commented Jan 11, 2020

Can you please verify if this is now fixed with last version of axios?

@usb248
Copy link

usb248 commented Jan 11, 2020

I tried, it works now 👍

@pi0 pi0 closed this as completed Jan 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants