question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Order of applying request interceptors is reversed.

See original GitHub issue

I’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:closed
  • Created 6 years ago
  • Reactions:6
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
rubennortecommented, Aug 12, 2017

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?

0reactions
le0nikcommented, Aug 12, 2017
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found