Angular HttpClient interceptor error‑handling pipeline: ambiguous order
0 reputation · 27 May 2022, 16:23 UTC
0 reputation · 27 May 2022, 16:23 UTC
To understand how Angular’s HttpClient interceptor chain processes errors when multiple interceptors are registered.
Angular invokes interceptors sequentially. When an interceptor returns a non‑null response, the chain is short‑circuited for success paths. For errors, the spec does not state a deterministic order among interceptors that handle the same error, leading to inconsistent error‑response transformations.
The current implementation may allow any interceptor that throws or returns a failed observable to capture the error, but the order in which they run is undocumented. This uncertainty can cause subtle bugs in logging, retry logic, or user‑facing error messages.
34775 reputation · 27 May 2022, 17:15 UTC
Angular executes HttpClient interceptors in the exact order they are registered; there is no documented priority for error‑handling interceptors, and retryWhen causes the whole chain to run again on the resubmitted request.
Because the spec only describes short‑circuiting on success, it is possible that different interceptors affect each other’s side‑effects, but the order in which they observe the error remains the registration sequence.
Please share the exact registration order of your HttpInterceptor providers (the list as it appears in the module file). This information is needed to determine whether the current order could cause duplicate side‑effects or missed logging when retryWhen is used.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.