@@ -53,6 +53,7 @@ export class ApiInstance {
5353 options : config . defaultOptions ?? { } ,
5454 optionsInit : { ...config . defaultOptions } ,
5555 timeout : config . timeout || undefined ,
56+ abortOnTimeout : config . abortOnTimeout ?? false ,
5657 baseURL :
5758 baseURL . endsWith ( '/' ) && baseURL . length > 1
5859 ? baseURL . substring ( 0 , baseURL . length - 1 )
@@ -113,10 +114,13 @@ export class ApiInstance {
113114 : `${ this . _internalStore . baseURL } ${
114115 path . startsWith ( '/' ) || path ?. length === 0 ? path : `/${ path } `
115116 } `
117+
118+ const controller = new AbortController ( )
116119 const requestObject = {
117120 ...this . _internalStore . options ,
118121 ...options ,
119122 headers,
123+ signal : controller . signal ,
120124 }
121125 // if we have a timeout set, call fetch and set a timeout. If the fetch takes longer than the timeout length, kill thee request and return a blank response
122126 if ( this . _internalStore . timeout ) {
@@ -142,6 +146,8 @@ export class ApiInstance {
142146 if ( raceResult ) {
143147 res = raceResult
144148 } else {
149+ if ( this . _internalStore . abortOnTimeout ) controller . abort ( )
150+
145151 // if we're throwing, throw an error
146152 if ( this . _internalStore . throws ) throw new Error ( 'Request timed out' )
147153 // a 504 response status means the programmatic timeout was surpassed
@@ -306,7 +312,7 @@ export class ApiInstance {
306312 */
307313 async post <
308314 ResponseType = any ,
309- BodyType extends Record < string , any > | string = { } ,
315+ BodyType extends Record < string , any > | string = { }
310316 > (
311317 path : string ,
312318 body : BodyType = { } as BodyType ,
@@ -459,7 +465,7 @@ export class ApiInstance {
459465 setHeaders <
460466 HeaderFunction extends ( ) =>
461467 | Record < string , any >
462- | Promise < Record < string , any > > ,
468+ | Promise < Record < string , any > >
463469 > ( inputFnOrObj : HeaderFunction | Record < string , any > ) {
464470 // if (!_headers) _internalStore._options.headers = {}
465471 if ( this . _internalStore . noFetch ) return this
0 commit comments