Skip to content

Commit

Permalink
fix: clear abort timeout after response was received
Browse files Browse the repository at this point in the history
  • Loading branch information
daniluk4000 committed Mar 1, 2024
1 parent 27996d3 commit 194c886
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/fetch.ts
Expand Up @@ -149,10 +149,12 @@ export function createFetch(globalOptions: CreateFetchOptions = {}): $Fetch {
}
}

let abortTimeout: number | undefined;

// TODO: Can we merge signals?
if (!context.options.signal && context.options.timeout) {
const controller = new AbortController();
setTimeout(() => controller.abort(), context.options.timeout);
abortTimeout = setTimeout(() => controller.abort(), context.options.timeout);
context.options.signal = controller.signal;
}

Expand All @@ -161,7 +163,9 @@ export function createFetch(globalOptions: CreateFetchOptions = {}): $Fetch {
context.request,
context.options as RequestInit
);
clearTimeout(abortTimeout);
} catch (error) {
clearTimeout(abortTimeout);
context.error = error as Error;
if (context.options.onRequestError) {
await context.options.onRequestError(context as any);
Expand Down

0 comments on commit 194c886

Please sign in to comment.