Import it from ky.
tstype Hooks = { … }
Properties
| Name | Type | Default | Description |
|---|---|---|---|
init? | readonly InitHook[] | undefined | [] | This hook enables you to modify the options before they are used to construct the request. The hook function receives the mutable options object and can modify it in place. You could, for example, modify searchParams, headers, or json here. The headers option is always a plain object with lowercase names, where a header removed with undefined keeps an undefined value. |
beforeRequest? | readonly BeforeRequestHook[] | undefined | [] | This hook enables you to modify the request right before it is sent. Ky will make no further changes to the request after this. The hook function receives a state object with the normalized request, options, and retry count. You could, for example, modify request.headers here. |
beforeRetry? | readonly BeforeRetryHook[] | undefined | [] | This hook enables you to modify the request right before retry. Ky will make no further changes to the request after this. The hook function receives a state object with the normalized request, options, an error instance, and retry count. You could, for example, modify request.headers here. |
beforeError? | readonly BeforeErrorHook[] | undefined | [] | This hook enables you to modify any error right before it is thrown. The hook function receives a state object with the current request, the normalized Ky options, the error, and retry count, and should return an Error instance. |
afterResponse? | readonly AfterResponseHook[] | undefined | [] | This hook enables you to read and optionally modify the response. The hook function receives a state object with the normalized request, options, a clone of the response, and retry count. The return value of the hook function will be used by Ky as the response object if it's an instance of Response. |
Was this page helpful?