@@ -157,7 +157,7 @@ async function makeFetchRequest<T>(requestParameters: RequestParameters, signal?
157157 if ( ( err as Error ) . message !== 'SecurityError' ) warnOnce ( ( err as Error ) . toString ( ) ) ;
158158 }
159159 if ( cached && cached . fresh ) {
160- if ( signal && signal . aborted ) throw new DOMException ( 'Aborted' , 'AbortError' ) ;
160+ if ( signal ) signal . throwIfAborted ( ) ;
161161 return readResponse < T > ( requestParameters , cached . response ) ;
162162 }
163163 }
@@ -173,7 +173,7 @@ async function makeFetchRequest<T>(requestParameters: RequestParameters, signal?
173173 throw new Error ( `${ ( err as Error ) . message } ${ requestParameters . url } ` , { cause : err } ) ;
174174 }
175175
176- if ( signal && signal . aborted ) throw new DOMException ( 'Aborted' , 'AbortError' ) ;
176+ if ( signal ) signal . throwIfAborted ( ) ;
177177 if ( ! fetched . ok ) throw new AJAXError ( fetched . statusText , fetched . status , requestParameters . url ) ;
178178
179179 // Clone before reading the body; cache the clone after the read completes. Aborting
@@ -195,7 +195,7 @@ async function makeXMLHttpRequest<T>(requestParameters: RequestParameters, signa
195195 const onAbort = ( ) => {
196196 signal . removeEventListener ( 'abort' , onAbort ) ;
197197 xhr . abort ( ) ;
198- reject ( new DOMException ( 'Aborted' , 'AbortError' ) ) ;
198+ reject ( signal . reason as Error ) ;
199199 } ;
200200
201201 if ( signal ) {
@@ -253,9 +253,7 @@ async function makeXMLHttpRequest<T>(requestParameters: RequestParameters, signa
253253}
254254
255255async function makeRequest < T > ( requestParameters : RequestParameters , signal ?: AbortSignal ) : Promise < RequestResponse < T > > {
256- if ( signal && signal . aborted ) {
257- throw new DOMException ( 'Aborted' , 'AbortError' ) ;
258- }
256+ if ( signal ) signal . throwIfAborted ( ) ;
259257
260258 if ( isFileURL ( requestParameters . url ) ) {
261259 return makeXMLHttpRequest < T > ( requestParameters , signal ) ;
@@ -299,7 +297,7 @@ resetImageRequestQueue();
299297function acquireImageRequest ( signal ?: AbortSignal ) : Promise < ( ) => void > {
300298 return new Promise ( ( resolve , reject ) => {
301299 if ( signal && signal . aborted ) {
302- reject ( new DOMException ( 'Aborted' , 'AbortError' ) ) ;
300+ reject ( signal . reason as Error ) ;
303301 return ;
304302 }
305303
@@ -327,7 +325,7 @@ function acquireImageRequest(signal?: AbortSignal): Promise<() => void> {
327325 const cancel = ( ) => {
328326 const index = imageRequestQueue . indexOf ( dequeue ) ;
329327 if ( index !== - 1 ) imageRequestQueue . splice ( index , 1 ) ;
330- reject ( new DOMException ( 'Aborted' , 'AbortError' ) ) ;
328+ reject ( signal . reason as Error ) ;
331329 } ;
332330
333331 if ( signal ) signal . addEventListener ( 'abort' , cancel ) ;
@@ -354,9 +352,7 @@ export async function getImage(requestParameters: RequestParameters, signal?: Ab
354352 throw new Error ( `Could not load image because of ${ ( e as Error ) . message } . Please make sure to use a supported image type such as PNG or JPEG. Note that SVGs are not supported.` , { cause : e } ) ;
355353 }
356354 // A late-resolving body must not deliver after abort, or it resurrects torn-down ImageSource state.
357- if ( signal && signal . aborted ) {
358- throw new DOMException ( 'Aborted' , 'AbortError' ) ;
359- }
355+ if ( signal ) signal . throwIfAborted ( ) ;
360356 return { data : bitmap , headers} ;
361357 } finally {
362358 release ( ) ;
0 commit comments