Skip to content

Commit

Permalink
fix(client): use AbortController in axios client
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanshatford committed Mar 23, 2024
1 parent f83279c commit 83e91c9
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/templates/core/axios/sendRequest.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ export const sendRequest = async <T>(
onCancel: OnCancel,
axiosClient: AxiosInstance
): Promise<AxiosResponse<T>> => {
const source = axios.CancelToken.source();
const controller = new AbortController();

const requestConfig: AxiosRequestConfig = {
url,
headers,
data: body ?? formData,
method: options.method,
withCredentials: config.WITH_CREDENTIALS,
cancelToken: source.token,
signal: controller.signal,
};

onCancel(() => source.cancel('The user aborted a request.'));
onCancel(() => controller.abort());

try {
return await axiosClient.request(requestConfig);
Expand Down

0 comments on commit 83e91c9

Please sign in to comment.