You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
It is impossible to define runWhen function for response interceprtors.
Describe the solution you'd like
I would love to have the possibility of defining the runWhen option for response interceptors
Describe alternatives you've considered
http.interceptors.response.use((response)=>{constmessage=response.data?.message;if(message&&response.config.notify){Notify.create({position: 'top',color: 'positive',message: message,icon: 'fal fa-info-circle'});}returnPromise.resolve(response);},(error)=>{if(error.config.notify){letmessage='';if(error.response&&error.response.data.message){message=error.response.data.message;}elseif(error.request){message='No response';}else{// Something happened in setting up the request that triggered an Errormessage=`Unknown error: ${error.message}`;}Notify.create({position: 'top',color: 'negative',message: message,icon: 'fal fa-exclamation-circle'});}returnPromise.reject(error);});
I ran into that problem while configuring the response interceptors too.
The runWhen function you parsed into the options is simply not invoked when axios adds the response interceptors to the chain. See the following snippet from the source code(lib/core/Axios.js line 79 ~ 94).
I have no idea why it was designed so but you can actually set the runWhen function as an option without getting an error with TypeScript. The request interceptors and the response interceptors share a common InterceptorManager class, and they are typed consistently.
btw, the request interceptors are invoked in the reversed order, notice that unshift is used. This is not mentioned in the docs, but I found it in the interceptors test at test/specs/interceptors.spec.js.
/* request interceptors have a reversed execution order */
There are several issues and pull requests related to this feature. It's still not documented or changed, together with the runWhen problem.
Maybe you can workaround it by modifying the source by now. Here's a forked version I did, hope it can be helpful. npm - axios-no-reverse. Note that I also changed the execution order of request interceptors.
Ping in 2023 for understanding the rationale here of runWhen on requests only but not on responses, besides the docs needs updating yup, found this closed issue #4228 which should be reopened, latest axios here v1.2.3 seems to lack support still
Thanks for the issue, we are adding this as a potential feature to a mega-feature issue with many feature requests please see the motivation for doing this:
Activity
shepard-liu commentedon Jul 22, 2022
I ran into that problem while configuring the response interceptors too.
The
runWhenfunction you parsed into the options is simply not invoked when axios adds the response interceptors to the chain. See the following snippet from the source code(lib/core/Axios.jsline 79 ~ 94).I have no idea why it was designed so but you can actually set the
runWhenfunction as an option without getting an error with TypeScript. The request interceptors and the response interceptors share a commonInterceptorManagerclass, and they are typed consistently.btw, the request interceptors are invoked in the reversed order, notice that
unshiftis used. This is not mentioned in the docs, but I found it in the interceptors test attest/specs/interceptors.spec.js./* request interceptors have a reversed execution order */There are several issues and pull requests related to this feature. It's still not documented or changed, together with the
runWhenproblem.Maybe you can workaround it by modifying the source by now. Here's a forked version I did, hope it can be helpful. npm - axios-no-reverse. Note that I also changed the execution order of request interceptors.
twbagustin commentedon Jan 19, 2023
Ping in 2023 for understanding the rationale here of
runWhenon requests only but not on responses, besides the docs needs updating yup, found this closed issue #4228 which should be reopened, latest axios here v1.2.3 seems to lack support stillagroves333 commentedon Aug 25, 2023
+1
jasonsaayman commentedon Jul 30, 2025
Thanks for the issue, we are adding this as a potential feature to a mega-feature issue with many feature requests please see the motivation for doing this:
#6983
And the mega-feature issue here:
#6984