|
8 | 8 | PlexusApiSendOptions, |
9 | 9 | PlexusApiFetchOptions, |
10 | 10 | } from './types' |
| 11 | +import { PlexusError } from '@plexusjs/utils' |
11 | 12 | // let's get Blob from Node.js or browser |
12 | 13 | let Blob |
13 | 14 | if (typeof window === 'undefined') { |
@@ -53,7 +54,7 @@ export class ApiInstance { |
53 | 54 | options: config.defaultOptions ?? {}, |
54 | 55 | optionsInit: { ...config.defaultOptions }, |
55 | 56 | timeout: config.timeout || undefined, |
56 | | - abortOnTimeout: config.abortOnTimeout ?? false, |
| 57 | + abortOnTimeout: config.abortOnTimeout ?? true, |
57 | 58 | baseURL: |
58 | 59 | baseURL.endsWith('/') && baseURL.length > 1 |
59 | 60 | ? baseURL.substring(0, baseURL.length - 1) |
@@ -149,7 +150,8 @@ export class ApiInstance { |
149 | 150 | if (this._internalStore.abortOnTimeout) controller.abort() |
150 | 151 |
|
151 | 152 | // 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' }) |
153 | 155 | // a 504 response status means the programmatic timeout was surpassed |
154 | 156 | return ApiInstance.createEmptyRes<ResponseDataType>( |
155 | 157 | timedOut ? 504 : res?.status ?? 513 |
@@ -312,7 +314,7 @@ export class ApiInstance { |
312 | 314 | */ |
313 | 315 | async post< |
314 | 316 | ResponseType = any, |
315 | | - BodyType extends Record<string, any> | string = {} |
| 317 | + BodyType extends Record<string, any> | string = {}, |
316 | 318 | >( |
317 | 319 | path: string, |
318 | 320 | body: BodyType = {} as BodyType, |
@@ -465,7 +467,7 @@ export class ApiInstance { |
465 | 467 | setHeaders< |
466 | 468 | HeaderFunction extends () => |
467 | 469 | | Record<string, any> |
468 | | - | Promise<Record<string, any>> |
| 470 | + | Promise<Record<string, any>>, |
469 | 471 | >(inputFnOrObj: HeaderFunction | Record<string, any>) { |
470 | 472 | // if (!_headers) _internalStore._options.headers = {} |
471 | 473 | if (this._internalStore.noFetch) return this |
|
0 commit comments