Skip to content

Commit f901b6e

Browse files
committed
abortOnTimeout is on by default
1 parent 03323c6 commit f901b6e

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

packages/plexus-api/src/api.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
PlexusApiSendOptions,
99
PlexusApiFetchOptions,
1010
} from './types'
11+
import { PlexusError } from '@plexusjs/utils'
1112
// let's get Blob from Node.js or browser
1213
let Blob
1314
if (typeof window === 'undefined') {
@@ -53,7 +54,7 @@ export class ApiInstance {
5354
options: config.defaultOptions ?? {},
5455
optionsInit: { ...config.defaultOptions },
5556
timeout: config.timeout || undefined,
56-
abortOnTimeout: config.abortOnTimeout ?? false,
57+
abortOnTimeout: config.abortOnTimeout ?? true,
5758
baseURL:
5859
baseURL.endsWith('/') && baseURL.length > 1
5960
? baseURL.substring(0, baseURL.length - 1)
@@ -149,7 +150,8 @@ export class ApiInstance {
149150
if (this._internalStore.abortOnTimeout) controller.abort()
150151

151152
// if we're throwing, throw an error
152-
if (this._internalStore.throws) throw new Error('Request timed out')
153+
if (this._internalStore.throws)
154+
throw new PlexusError('Request timed out', { type: 'api' })
153155
// a 504 response status means the programmatic timeout was surpassed
154156
return ApiInstance.createEmptyRes<ResponseDataType>(
155157
timedOut ? 504 : res?.status ?? 513
@@ -312,7 +314,7 @@ export class ApiInstance {
312314
*/
313315
async post<
314316
ResponseType = any,
315-
BodyType extends Record<string, any> | string = {}
317+
BodyType extends Record<string, any> | string = {},
316318
>(
317319
path: string,
318320
body: BodyType = {} as BodyType,
@@ -465,7 +467,7 @@ export class ApiInstance {
465467
setHeaders<
466468
HeaderFunction extends () =>
467469
| Record<string, any>
468-
| Promise<Record<string, any>>
470+
| Promise<Record<string, any>>,
469471
>(inputFnOrObj: HeaderFunction | Record<string, any>) {
470472
// if (!_headers) _internalStore._options.headers = {}
471473
if (this._internalStore.noFetch) return this

0 commit comments

Comments
 (0)