softonic / axios-retry

Axios plugin that intercepts failed requests and retries them whenever possible
Other
1.89k stars 167 forks source link

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

Closed zhen-one closed 5 months ago

zhen-one commented 7 months ago

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 commented 6 months ago

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 commented 5 months ago

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

obscurecat64 commented 5 months ago

@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: https://github.com/softonic/axios-retry/pull/272#issuecomment-2115781228) please 🙏

mindhells commented 5 months ago

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