Angular Http Interceptor 使用情境很多,例如加 header token、處理 response error 等,但有時候如果真的有 http request 想要跳過 interceptor 這層該怎麼處理,以下是處理手法
程式碼
這裡會利用 HttpBackend
來完成
Interceptors sit between the
HttpClient
interface and theHttpBackend
.When injected,
HttpBackend
dispatches requests directly to the backend, without going through the interceptor chain.
HttpClient
原始碼
1 | () |
HttpBackend
interface
1 | abstract class HttpBackend implements HttpHandler { |
範例程式
1 | import {HttpBackend, HttpClient} from '@angular/common/http'; |
手動建立一個 HttpClient
,之後透過這個 httpClient
的 request 就不會經過 Interceptor 那層,就是這麼簡單