Axios-module: axios-retry problem with baseURL

Created on 5 Mar 2018  路  6Comments  路  Source: nuxt-community/axios-module

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)
bug

Most helpful comment

I tried, it works now 馃憤

All 6 comments

Is this bug fixed yet?

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

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

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

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

I tried, it works now 馃憤

Was this page helpful?
0 / 5 - 0 ratings

Related issues

artmarydotir picture artmarydotir  路  4Comments

lyzs90 picture lyzs90  路  4Comments

seanwash picture seanwash  路  6Comments

gammpamm picture gammpamm  路  4Comments

tebaly picture tebaly  路  3Comments