server: use AbortSignal.timeout

Using AbortSignal.timeout is a cleaner solution that using an
AbortController and triggering it ourselves with setTimeout.
This commit is contained in:
Johann150 2024-01-23 19:46:11 +01:00
parent b94aeb2df2
commit 6fd422f2b0
Signed by untrusted user: Johann150
GPG key ID: 9EE6577A2A06F8F1

View file

@ -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 (