Skip to content

Commit

Permalink
fix: type definition of onError hook's argument (#176)
Browse files Browse the repository at this point in the history
  • Loading branch information
harunorimurata authored Oct 4, 2021
1 parent b8e353f commit 43e209b
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,21 @@ type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;

type RequestBody = string | number | boolean | null | object | BodyInit

type HTTPError = ky.HTTPError & {
response: HTTPErrorResponse
statusCode?: number
}

type HTTPErrorResponse = Response & {
text: () => Promise<string>
json: () => Promise<any>
data: any
}

type OnErrorHook = (
error: HTTPError
) => void;

interface NuxtHTTPInstance {
/**
* Fetches the `url` with the option `{method: 'get'}`.
Expand Down Expand Up @@ -157,7 +172,7 @@ interface NuxtHTTPInstance {
*
* This hook enables you to globally handle request errors.
*/
onError(hook: (error: ky.HTTPError) => void): void
onError(hook: OnErrorHook): void

/**
* If you need to create your own ky instance which based on $http defaults, you can use the create(options) method.
Expand Down

0 comments on commit 43e209b

Please sign in to comment.