Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ Type: `string | URL`

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`.

Useful when used with [`ky.extend()`](#kyextenddefaultoptions) to create niche-specific Ky-instances.
Useful when used with [`ky.extend()`](#kyextenddefaultoptions) to create niche-specific Ky instances.

If the `baseUrl` itself is relative, it will be resolved against the environment's base URL, such as [`document.baseURI`](https://developer.mozilla.org/en-US/docs/Web/API/Node/baseURI) in browsers or `location.href` in Deno (see the `--location` flag).

Expand All @@ -246,7 +246,7 @@ Type: `string | URL`

A prefix to prepend to the `input` before making the request (and before it is resolved against the `baseUrl`). It can be any valid path or URL, either relative or absolute. A trailing slash `/` is optional and will be added automatically, if needed, when it is joined with `input`. Only takes effect when `input` is a string.

Useful when used with [`ky.extend()`](#kyextenddefaultoptions) to create niche-specific Ky-instances.
Useful when used with [`ky.extend()`](#kyextenddefaultoptions) to create niche-specific Ky instances.

*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.*

Expand Down Expand Up @@ -1057,7 +1057,7 @@ const options = {
}
};

// Note that response will be `undefined` in case `ky.stop` is returned.
// Note that `response` will be `undefined` in case `ky.stop` is returned.
const response = await ky.post('https://example.com', options);

// Using `.text()` or other body methods is not supported.
Expand Down
2 changes: 1 addition & 1 deletion source/core/Ky.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ export class Ky {
let processedError: Error = error;
for (const hook of ky.#options.hooks.beforeError) {
// `request` is the current failing request. `options` intentionally remains the
// stable normalized Ky options snapshot for the same reason as HTTPError above.
// stable normalized Ky options snapshot for the same reason as `HTTPError` above.
// eslint-disable-next-line no-await-in-loop
const hookResult: unknown = await hook({
request: ky.request,
Expand Down
4 changes: 2 additions & 2 deletions source/types/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export type KyOptions = {
/**
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`.

Useful when used with [`ky.extend()`](#kyextenddefaultoptions) to create niche-specific Ky-instances.
Useful when used with [`ky.extend()`](#kyextenddefaultoptions) to create niche-specific Ky instances.

If the `baseUrl` itself is relative, it will be resolved against the environment's base URL, such as [`document.baseURI`](https://developer.mozilla.org/en-US/docs/Web/API/Node/baseURI) in browsers or `location.href` in Deno (see the `--location` flag).

Expand All @@ -137,7 +137,7 @@ export type KyOptions = {
/**
A prefix to prepend to the `input` before making the request (and before it is resolved against the `baseUrl`). It can be any valid path or URL, either relative or absolute. A trailing slash `/` is optional and will be added automatically, if needed, when it is joined with `input`. Only takes effect when `input` is a string.

Useful when used with [`ky.extend()`](#kyextenddefaultoptions) to create niche-specific Ky-instances.
Useful when used with [`ky.extend()`](#kyextenddefaultoptions) to create niche-specific Ky instances.

*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.*

Expand Down
18 changes: 9 additions & 9 deletions source/utils/type-guards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const isErrorType = (error: unknown, cls: {name: string}): boolean =>
error instanceof (cls as any) || (error as any)?.name === cls.name;

/**
Type guard to check if an error is a Ky error.
Type guard to check if an error is a `KyError`.

Note: `SchemaValidationError` is intentionally not considered a Ky error. `KyError` covers failures in Ky's HTTP lifecycle (bad status, timeout, retry), while schema validation errors originate from the user-provided schema, not from Ky itself.

Expand Down Expand Up @@ -37,10 +37,10 @@ export function isKyError(error: unknown): error is KyError {
}

/**
Type guard to check if an error is an HTTPError.
Type guard to check if an error is an `HTTPError`.

@param error - The error to check
@returns `true` if the error is an HTTPError, `false` otherwise
@returns `true` if the error is an `HTTPError`, `false` otherwise

@example
```
Expand All @@ -59,10 +59,10 @@ export function isHTTPError<T = unknown>(error: unknown): error is HTTPError<T>
}

/**
Type guard to check if an error is a NetworkError.
Type guard to check if an error is a `NetworkError`.

@param error - The error to check
@returns `true` if the error is a NetworkError, `false` otherwise
@returns `true` if the error is a `NetworkError`, `false` otherwise

@example
```
Expand All @@ -81,10 +81,10 @@ export function isNetworkError(error: unknown): error is NetworkError {
}

/**
Type guard to check if an error is a TimeoutError.
Type guard to check if an error is a `TimeoutError`.

@param error - The error to check
@returns `true` if the error is a TimeoutError, `false` otherwise
@returns `true` if the error is a `TimeoutError`, `false` otherwise

@example
```
Expand All @@ -103,10 +103,10 @@ export function isTimeoutError(error: unknown): error is TimeoutError {
}

/**
Type guard to check if an error is a ForceRetryError.
Type guard to check if an error is a `ForceRetryError`.

@param error - The error to check
@returns `true` if the error is a ForceRetryError, `false` otherwise
@returns `true` if the error is a `ForceRetryError`, `false` otherwise

@example
```
Expand Down