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

Provide option to trigger retry from successful (200) response in Axios's response interceptors #267

Closed
zhen-one opened this issue Mar 21, 2024 · 4 comments

Comments

@zhen-one
Copy link

Reason:

Certain APIs consistently return a 200 HTTP code, with custom error codes embedded within the data payload

Like below

{
  "code": -1,
  "data":"...",
  "msg":"bad request"
}

Please add an option to decide whether to trigger retry from response or error.

axios.interceptors.response.use(function (response) {
    return response;
  }, function (error) {
    return Promise.reject(error);
  });
@andreww2012
Copy link

This option is also needed if using a custom validateStatus function like validateStatus: () => true. In such a case, the "error" response interceptor is never called (but the "success" one is).

@obscurecat64
Copy link
Contributor

@zhen-one you should be able to use the validateStatus function of axios together with retryCondition to accomplish this.

@obscurecat64
Copy link
Contributor

@zhen-one you should be able to use the validateStatus function of axios together with retryCondition to accomplish this.

apologies, in this case validateStatus is not enough. I've created a PR for this feature. Would like to hear your (or others') opinion on the usage (see: #272 (comment)) please 🙏

@mindhells
Copy link
Member

this should be now covered by #272 thanks to @obscurecat64
closing this issue

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

4 participants