From b6f335bc09edb0a665537fd605f594f365c2950f Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Thu, 21 Mar 2024 16:04:20 -0400 Subject: [PATCH] refactor: switch to using abort controller, and allow signal to be overridden --- src/axios.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/axios.ts b/src/axios.ts index da357ea..1b41741 100644 --- a/src/axios.ts +++ b/src/axios.ts @@ -9,7 +9,7 @@ export const customInstance = ( config: AxiosRequestConfig, options?: AxiosRequestConfig, ): CancelablePromise => { - const source = Axios.CancelToken.source(); + const abort = new AbortController(); /* Hack to ensure that the data is passed to the request as an option. @@ -22,9 +22,9 @@ export const customInstance = ( const instance = Axios.create({ baseURL: options?.baseURL }); const promise = instance({ + signal: abort.signal, ...config, ...options, - cancelToken: source.token, }) .then(({ data }) => data) .catch((error) => { @@ -39,7 +39,7 @@ export const customInstance = ( // @ts-ignore promise.cancel = () => { - source.cancel("Query was cancelled"); + abort.abort("Query was cancelled"); }; return promise as CancelablePromise;