Axios Request Cancellation: Transitioning from CancelToken to AbortController
24K reputation · 23 Nov 2021, 22:27 UTC
Cancellation Lifecycle Management
Axios version 1.x supports both the legacy CancelToken and the modern AbortController API for terminating pending requests. While AbortController is the web standard, the internal handling of the cancellation signal varies across different adapter environments.
When integrating AbortController signals into a request configuration, there is uncertainty regarding how the signal propagates through the interceptor chain. Specifically, if a request is aborted, the behavior of the response interceptor's error handler differs depending on whether a CancelToken or an AbortSignal was used to trigger the termination.
- Consistency of the error object returned to the
.catch()block. - The timing of the abort signal detection within the request interceptor sequence.
Does the AbortController implementation consistently trigger the same error-handling path as CancelToken across all supported adapters? How should the response interceptor distinguish between a manual abort and a network-level timeout when using signals?