Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Order of HttpInterceptors

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?

like image 976
Fernando Avatar asked Jul 04 '18 13:07

Fernando


2 Answers

https://angular.io/guide/http#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.

like image 190
Talmid Avatar answered Oct 11 '22 17:10

Talmid


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.

like image 13
Antoniossss Avatar answered Oct 11 '22 19:10

Antoniossss