Order of applying request interceptors is reversed.
See original GitHub issueI’ve encountered a bug(or a feature) that my request interceptors were applied in reversed order.
This is the culprit: https://github.com/mzabriskie/axios/blob/2fe95621b0e4839f489210452ffc6d2cb0f90343/lib/core/Axios.js#L48
If you unshift
interceptors one by one, then the last defined interceptor becomes the first in the chain
.
Example:
axios.interceptors.request.use(config => {
console.log('First');
return config;
});
axios.interceptors.request.use(config => {
console.log('Second');
return config;
});
When we perform a request this is what we see in the console:
> Second
> First
If it’s intentional, I think it should be documented.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:6
- Comments:5 (1 by maintainers)
Top Results From Across the Web
What is the order of execution of $http interceptors in ...
It seems that the interceptors are executed: in registration order for requests; in reverse registration order for responses. Log:
Read more >Introduction to CORBA Request-Level Interceptors
The ORB then calls each of the registered interceptors in a sequence that's the reverse of the order in which they were called...
Read more >OkHttp Logging and Order of Interceptors | by Herman Cheung
OkHttp interceptor is a powerful mechanism to customise its behaviour. We may intercept the HTTP requests and responses, modify them.
Read more >Interceptors — tapir 1.x documentation - SoftwareMill
Request interceptors for two common scenarios can be created using the RequestInterceptor. ... handling of the result will be done in opposite order....
Read more >Angular Interceptors - The Complete Guide
To bypass the chain, we simply inject the HttpBackend handler and provide it to a local HttpClient instance. Using this instance to make...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
As this isn’t documented nor tested isn’t actually a bug, but I understand it should be executed in the proper order.
The tests for response interceptors test the actual order but those for the request don’t.
Are you willing to create a PR to solve this?
Sure. PR: https://github.com/mzabriskie/axios/pull/1041