Skip to content

Commit 0dd9522

Browse files
committed
Various tweaks
1 parent c20d7c7 commit 0dd9522

11 files changed

Lines changed: 686 additions & 161 deletions

File tree

readme.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,12 +576,14 @@ const response = await ky('https://example.com/api', {
576576
Type: `Function[]`\
577577
Default: `[]`
578578

579-
This hook enables you to modify any error right before it is thrown. The hook function receives a state object with the normalized request, options, error, and retry count, and should return an `Error` instance.
579+
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, error, and retry count, and should return an `Error` instance.
580580

581581
This hook is called for all error types, including `HTTPError`, `NetworkError`, `TimeoutError`, and `ForceRetryError` (when retry limit is exceeded via `ky.retry()`). Use type guards like `isHTTPError()`, `isNetworkError()`, or `isTimeoutError()` to handle specific error types.
582582

583583
The `retryCount` is `0` for the initial request and increments with each retry. This allows you to distinguish between the initial request and retries, which is useful when you need different error handling based on retry attempts (e.g., showing different error messages on the final attempt).
584584

585+
If a `beforeRequest` or `beforeRetry` hook returns a new `Request`, inspect `request` for the final request state. `options` remains Ky's normalized options and may not mirror every property of a replacement `Request`.
586+
585587
```js
586588
import ky, {isHTTPError} from 'ky';
587589

0 commit comments

Comments
 (0)