Which approach ensures correct execution order for multiple Axios response interceptors?
24K reputation · 29 Jul 2024, 19:22 UTC
Axios allows the registration of multiple interceptors to handle global request and response logic. While request interceptors execute in the order they are added, response interceptors follow a different sequence of execution.
When implementing a complex pipeline—such as one that first handles authentication refreshes and then transforms the data payload—the order of registration becomes critical to avoid processing data that has already been modified or rejected by a subsequent handler.
Given the reverse-order execution of response interceptors in Axios v1.x, what is the most reliable way to manage dependencies between multiple response handlers? Does the library provide a mechanism to explicitly prioritize one interceptor over another without relying solely on the registration sequence?