You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: readme.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -28,7 +28,7 @@ It's just a tiny package with no dependencies.
28
28
- Base URL option
29
29
- Instances with custom defaults
30
30
- Hooks
31
-
- TypeScript niceties (e.g. `.json()` supports generics and defaults to `unknown`, not `any`)
31
+
- TypeScript niceties (e.g.,`.json()` supports generics and defaults to `unknown`, not `any`)
32
32
33
33
## Install
34
34
@@ -197,7 +197,7 @@ When passing an object, setting a value to `undefined` deletes the parameter, wh
197
197
198
198
Type: `string | URL`
199
199
200
-
A base URL to [resolve](https://developer.mozilla.org/en-US/docs/Web/API/URL_API/Resolving_relative_references) the `input` against. When the `input` (after applying the `prefix` option) is only a relative URL, such as `'users'`, `'/users'`, or `'//my-site.com'`, it will be resolved against the `baseUrl` to determine the destination of the request. Otherwise, the `input` is absolute, such as `'https://my-site.com'`, and it will bypass the `baseUrl`.
200
+
A base URL to [resolve](https://developer.mozilla.org/en-US/docs/Web/API/URL_API/Resolving_relative_references) the `input` against. When the `input` (after applying the `prefix` option) is only a relative URL, such as `'users'`, `'/users'`, or `'//my-site.com'`, it will be resolved against the `baseUrl` to determine the destination of the request. Otherwise, the `input` is absolute, such as `'https://my-site.com'`, and it will bypass the `baseUrl`.
201
201
202
202
Useful when used with [`ky.extend()`](#kyextenddefaultoptions) to create niche-specific Ky-instances.
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.
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, the error, and retry count, and should return an `Error` instance.
580
580
581
581
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.
582
582
@@ -1207,7 +1207,7 @@ It also has a `data` property with the pre-parsed response body. For JSON respon
1207
1207
Be aware that some types of errors, such as network errors, inherently mean that a response was not received. In that case, the error will be an instance of [`NetworkError`](#networkerror) instead of `HTTPError` and will not contain a `response` property.
1208
1208
1209
1209
> [!NOTE]
1210
-
> The response body is automatically consumed when populating `error.data`, so you do not need to manually consume or cancel`error.response.body`.
1210
+
> The response body is automatically consumed when populating `error.data`, so `error.response.json()` and other body methods will not work. Use`error.data` instead. The `error.response` object is still available for headers, status, etc.
Copy file name to clipboardExpand all lines: source/core/Ky.ts
+3-3Lines changed: 3 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -150,7 +150,7 @@ export class Ky {
150
150
continue;
151
151
}
152
152
153
-
// Opaque responses (`response.type === 'opaque'`) from `no-cors` requests always have `status: 0` and `ok: false`, but this is not a failure — the actual status is hidden by the browser.
153
+
// Opaque responses (`response.type === 'opaque'`) from `no-cors` requests always have `status: 0` and `ok: false`, but this is not a failure - the actual status is hidden by the browser.
154
154
if(!response.ok&&response.type!=='opaque'&&(
155
155
typeofky.#options.throwHttpErrors==='function'
156
156
? ky.#options.throwHttpErrors(response.status)
@@ -205,7 +205,7 @@ export class Ky {
205
205
try{
206
206
returnawaitfunction_();
207
207
}catch(error: unknown){
208
-
// Non-Error throws (e.g. thrown strings) pass through unchanged
208
+
// Non-Error throws (e.g., thrown strings) pass through unchanged
Copy file name to clipboardExpand all lines: source/errors/HTTPError.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ import {KyError} from './KyError.js';
6
6
/**
7
7
Error thrown when the response has a non-2xx status code and `throwHttpErrors` is enabled.
8
8
9
-
The error has a `response` property with the `Response` object, a `request` property with the `Request` object, an `options` property with the normalized options, and a `data` property with the pre-parsed response body.
9
+
The error has a `response` property with the `Response` object, a `request` property with the `Request` object, an `options` property with the normalized options, and a `data` property with the pre-parsed response body. The response body is automatically consumed when populating `data`, so `response.json()` and other body methods will not work. Use `data` instead.
Copy file name to clipboardExpand all lines: source/types/ResponsePromise.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
/**
2
-
Returns a `Response` object with `Body` methods added for convenience. So you can, for example, call `ky.get(input).json()` directly without having to await the `Response` first. When called like that, an appropriate `Accept` header will be set depending on the body method used. Unlike the `Body` methods of `window.Fetch`; these will throw an `HTTPError` if the response status is not in the range of `200...299`. Also, `.json()` will return `undefined` if body is empty or the response status is `204` instead of throwing a parse error due to an empty body.
2
+
Returns a `Response` object with `Body` methods added for convenience. So you can, for example, call `ky.get(input).json()` directly without having to await the `Response` first. When called like that, an appropriate `Accept` header will be set depending on the body method used. Unlike the `Body` methods of `window.fetch`, these will throw an `HTTPError` if the response status is not in the range of `200...299`. Also, `.json()` will return `undefined` if body is empty or the response status is `204` instead of throwing a parse error due to an empty body.
Copy file name to clipboardExpand all lines: source/types/options.ts
+3-3Lines changed: 3 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -111,7 +111,7 @@ export type KyOptions = {
111
111
searchParams?: SearchParamsOption;
112
112
113
113
/**
114
-
A base URL to [resolve](https://developer.mozilla.org/en-US/docs/Web/API/URL_API/Resolving_relative_references) the `input` against. When the `input` (after applying the `prefix` option) is only a relative URL, such as `'users'`, `'/users'`, or `'//my-site.com'`, it will be resolved against the `baseUrl` to determine the destination of the request. Otherwise, the `input` is absolute, such as `'https://my-site.com'`, and it will bypass the `baseUrl`.
114
+
A base URL to [resolve](https://developer.mozilla.org/en-US/docs/Web/API/URL_API/Resolving_relative_references) the `input` against. When the `input` (after applying the `prefix` option) is only a relative URL, such as `'users'`, `'/users'`, or `'//my-site.com'`, it will be resolved against the `baseUrl` to determine the destination of the request. Otherwise, the `input` is absolute, such as `'https://my-site.com'`, and it will bypass the `baseUrl`.
115
115
116
116
Useful when used with [`ky.extend()`](#kyextenddefaultoptions) to create niche-specific Ky-instances.
117
117
@@ -142,8 +142,8 @@ export type KyOptions = {
142
142
*In most cases, you should use the `baseUrl` option instead, as it is more consistent with web standards. However, `prefix` is useful if you want origin-relative `input` URLs, such as `/users`, to be treated as if they were page-relative. In other words, the leading slash of the `input` will essentially be ignored, because the `prefix` will become part of the `input` before URL resolution happens.*
143
143
144
144
Notes:
145
-
- The `prefix` and `input` are joined with a slash `/`, and slashes are normalized at the join boundary by trimming trailing slashes from `prefix` and leading slashes from `input`.
146
-
- After `prefix` and `input` are joined, the result is resolved against the `baseUrl` option, if present.
145
+
- The `prefix` and `input` are joined with a slash `/`, and slashes are normalized at the join boundary by trimming trailing slashes from `prefix` and leading slashes from `input`.
146
+
- After `prefix` and `input` are joined, the result is resolved against the `baseUrl` option, if present.
0 commit comments