Order of HttpInterceptors
Asked Answered
C

2

25

I have a application that uses a plugin that register a HttpInterceptor.

Now I need to create my own interceptor that need to be run before the other interceptor because it will change some values, in localStorage, that the other interceptor uses.

How can I influence in the execution order when registering a new HttpInterceptor?

Charlinecharlock answered 4/7, 2018 at 13:10 Comment(1)
angular.io/guide/http#interceptor-orderBattleax
C
16

You cannot set interceptors order. Interceptors are chained in order they are declared.

You will have write your own super interceptor that will allow to append child interceptors with some ordering logic.

Cressi answered 4/7, 2018 at 13:17 Comment(4)
So what you're saying is that you can set interceptors order by declaring them in a specific order.Confirm
caso um dos interceptors esteja em um modulo e outro nao como fica essa ordemChafe
Please delete your answer, this is not true.Martensite
This answer is true, if OP need to change the order dynamically.Cambrian
C
21

https://angular.io/guide/http-intercept-requests-and-responses#interceptor-order

Angular applies interceptors in the order that you provide them. If you provide interceptors A, then B, then C, requests flow in A->B->C and responses flow out C->B->A.

Colleencollege answered 15/1, 2021 at 17:18 Comment(0)
C
16

You cannot set interceptors order. Interceptors are chained in order they are declared.

You will have write your own super interceptor that will allow to append child interceptors with some ordering logic.

Cressi answered 4/7, 2018 at 13:17 Comment(4)
So what you're saying is that you can set interceptors order by declaring them in a specific order.Confirm
caso um dos interceptors esteja em um modulo e outro nao como fica essa ordemChafe
Please delete your answer, this is not true.Martensite
This answer is true, if OP need to change the order dynamically.Cambrian

© 2022 - 2024 — McMap. All rights reserved.