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 request problem #2833

Closed
gitzhangliang opened this issue Mar 20, 2020 · 3 comments
Closed

retry request problem #2833

gitzhangliang opened this issue Mar 20, 2020 · 3 comments

Comments

@gitzhangliang
Copy link

gitzhangliang commented Mar 20, 2020

when i use axios.interceptors.response ,when check code of backserver return is 401, I refresh token and i retry the previous request. the code like this:
axios.interceptors.response.use( response => { const { data } = response; switch (parseInt(data.code)) { case 401: var newToken = ...; response.config.Authentication =newToken ; return axios.request(response.config) break; default: break; } return response; }, error => { .... } } );
and i have a setting: axios.defaults.baseURL = "/api"
one correct like this [/api/listUser],but when i retry request. the url is [/api/api/listUser], i do not know why [/api] appear twice . so the response is 404.

@gitzhangliang
Copy link
Author

i us e#1628 way. it works 。 like this:
response.config.baseURL = response.config.url;
response.config.url = '';
response.config.Authentication = res.data.token;
return axios.request(response.config)

@gitzhangliang
Copy link
Author

before webpack build:
response.config.baseUrl = "/api", response.config.url = "/api/getUser"
whole url = "/api/api/getUser",it is error.
i use #1628 way. it works. whole url = "/api/getUser",it is right
after webpack build:
response. config.baseUrl = "/api", response.config.url = "/getUser"
whole url = "/api/getUser",it is right.
when i use #1628 way. it don`t works. whole url = "/getUser",it is error.

so it is incompatible about before webpack build and after webpack build.

@chinesedfan
Copy link
Collaborator

Closed by the issue bot. Make sure you have followed the issue template.

Please open a new issue, instead of editing the current one. Maybe you can read chinesedfan/You-Dont-Know-Axios first.

@axios axios locked and limited conversation to collaborators May 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants