From 576a66460ff2f3d25a013890d28f4bb568e6ad82 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sun, 9 Feb 2025 14:45:26 -0600 Subject: [PATCH] fetchWorker: preemptively throw if signal is aborted --- src/workers/fetch.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/workers/fetch.ts b/src/workers/fetch.ts index bb5588ed..e1915fb4 100644 --- a/src/workers/fetch.ts +++ b/src/workers/fetch.ts @@ -27,6 +27,10 @@ const fetchWorker: typeof fetch = async (...args) => { const [url, init] = serializeFetchArgs(args); const { body, signal, ...rest } = init; + if (signal?.aborted) { + throw new DOMException('The signal has been aborted', 'AbortError'); + } + const result = await client.fetch(url, { ...rest, body: await prepareBodyForWorker(body) }, signal); const response = new Response(...result);