From 6fd422f2b09c9fc6449f5502cdd8b656d0d83c81 Mon Sep 17 00:00:00 2001 From: Johann150 Date: Tue, 23 Jan 2024 19:46:11 +0100 Subject: [PATCH] server: use AbortSignal.timeout Using AbortSignal.timeout is a cleaner solution that using an AbortController and triggering it ourselves with setTimeout. --- packages/backend/src/misc/fetch.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/packages/backend/src/misc/fetch.ts b/packages/backend/src/misc/fetch.ts index 4224589e6..403f15725 100644 --- a/packages/backend/src/misc/fetch.ts +++ b/packages/backend/src/misc/fetch.ts @@ -49,11 +49,6 @@ export async function getResponse(_args: { ..._args, }; - const controller = new AbortController(); - setTimeout(() => { - controller.abort(); - }, args.timeout); - const res = await fetch(args.url, { method: args.method, headers: Object.assign({ @@ -63,7 +58,7 @@ export async function getResponse(_args: { redirect: args.redirect, size: args.size, agent: getAgentByUrl, - signal: controller.signal, + signal: AbortSignal.timeout(args.timeout), }); if (