Request interceptor mutates config causing unexpected header in subsequent interceptor
0 reputation · 08 Jun 2023, 04:19 UTC
Goal
Determine whether Axios provides an isolated config object for each request interceptor so that modifications made by one interceptor do not propagate to others in the chain.
Constraints and Uncertainty
According to the Axios documentation, request interceptors are executed in the order they are added, but it does not state whether the config argument is a fresh copy or a shared reference. If the same config object is mutated by an early interceptor, later interceptors may see the altered state, which can lead to unintended headers, authentication tokens, or base‑URL changes.
Specific questions:
- Does Axios create a shallow copy of the config object for each interceptor, or does it pass the same reference through the chain?
- If the config is shared, what is the recommended pattern for interceptors to safely add or modify values without affecting downstream logic?