diff --git a/src/index.ts b/src/index.ts index b33660a..1a975f8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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, }) } diff --git a/src/types.ts b/src/types.ts index 18573d9..8fe5af8 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,6 +1,4 @@ -export type Nil = null | undefined | void - -export type Nilable = Nil | T +export type Nullable = T | null | undefined export type Readonlyable = Readonly | T @@ -22,7 +20,7 @@ export type URLSearchParamsInit = ConstructorParameters< >[0] export type URLSearchParamsOptions = - | Record>> + | Record>> | URLSearchParamsInit | object @@ -61,5 +59,6 @@ export type ApiInterceptor = ( export interface ResponseError extends Error { data?: T | null + request: Request response?: Response | null } diff --git a/src/utils.ts b/src/utils.ts index 7c5967a..e970155 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,5 +1,5 @@ import { - Nilable, + Nullable, ResponseType, URLSearchParamsOptions, ValueOf, @@ -22,7 +22,7 @@ export const cleanNilValues = (input: T, empty?: boolean): T => { for (const _key of Object.keys(input)) { const key = _key as keyof T - const value = input[key] as Nilable> + const value = input[key] as Nullable> if (empty ? !value : value == null) { delete input[key] } else {