axios의 github 리드미를 보면 CancelToken은 v0.22.0부터 deprecated되었다고 한다. (사용이 권장되지 않음)
(공식문서에도 해당 내용이 있음)
const controller = new AbortController();
axios.get(url, {
signal: controller.signal
}).then((res) => {
});
// cancel the request
controller.abort()
.catch((err) => {
if (err.name == 'AbortError') { // handle abort()
alert("Aborted!");
}
})
출처)
모던 자바스크립트 fetch-abort
abortcontroller-and-fetch-how-to-distinguish-network-error-from-abort-error