Skip to content

Commit

Permalink
fix: should await data, add request into error
Browse files Browse the repository at this point in the history
  • Loading branch information
JounQin committed Jan 30, 2024
1 parent 3565470 commit 4233c30
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ export const createFetchApi = (fetch = globalThis.fetch) => {
return response
}
throw Object.assign(new Error(response.statusText), {
data: extractDataFromResponse(response, type, true),
data: await extractDataFromResponse(response, type, true),
request,
response,
})
}
Expand Down
7 changes: 3 additions & 4 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
export type Nil = null | undefined | void

export type Nilable<T> = Nil | T
export type Nullable<T> = T | null | undefined

export type Readonlyable<T> = Readonly<T> | T

Expand All @@ -22,7 +20,7 @@ export type URLSearchParamsInit = ConstructorParameters<
>[0]

export type URLSearchParamsOptions =
| Record<string, Nilable<Arrayable<number | string>>>
| Record<string, Nullable<Arrayable<number | string>>>
| URLSearchParamsInit
| object

Expand Down Expand Up @@ -61,5 +59,6 @@ export type ApiInterceptor = (

export interface ResponseError<T = never> extends Error {
data?: T | null
request: Request
response?: Response | null
}
4 changes: 2 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
Nilable,
Nullable,
ResponseType,
URLSearchParamsOptions,
ValueOf,
Expand All @@ -22,7 +22,7 @@ export const cleanNilValues = <T = unknown>(input: T, empty?: boolean): T => {

for (const _key of Object.keys(input)) {
const key = _key as keyof T
const value = input[key] as Nilable<ValueOf<T>>
const value = input[key] as Nullable<ValueOf<T>>
if (empty ? !value : value == null) {
delete input[key]
} else {
Expand Down

0 comments on commit 4233c30

Please sign in to comment.