fetchWorker: preemptively throw if signal is aborted

This commit is contained in:
Alex Gleason 2025-02-09 14:45:26 -06:00
parent ebbde66824
commit 576a66460f
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7

View file

@ -27,6 +27,10 @@ const fetchWorker: typeof fetch = async (...args) => {
const [url, init] = serializeFetchArgs(args); const [url, init] = serializeFetchArgs(args);
const { body, signal, ...rest } = init; 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 result = await client.fetch(url, { ...rest, body: await prepareBodyForWorker(body) }, signal);
const response = new Response(...result); const response = new Response(...result);