fetchWorker: try throwing a preemptive AbortError inside the worker itself

This commit is contained in:
Alex Gleason 2025-02-09 14:52:43 -06:00
parent 93874df063
commit a98bfdd0c6
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7

View file

@ -13,6 +13,10 @@ export const FetchWorker = {
init: Omit<RequestInit, 'signal'>, init: Omit<RequestInit, 'signal'>,
signal: AbortSignal | null | undefined, signal: AbortSignal | null | undefined,
): Promise<[BodyInit, ResponseInit]> { ): Promise<[BodyInit, ResponseInit]> {
if (signal?.aborted) {
throw new DOMException('The signal has been aborted', 'AbortError');
}
logi({ level: 'debug', ns: 'ditto.fetch', state: 'started', method: init.method ?? 'GET', url }); logi({ level: 'debug', ns: 'ditto.fetch', state: 'started', method: init.method ?? 'GET', url });
const response = await safeFetch(url, { ...init, signal }); const response = await safeFetch(url, { ...init, signal });