diff --git a/docs/docs/GettingStarted.md b/docs/docs/GettingStarted.md index 7c3072839c6..829a5c9f580 100644 --- a/docs/docs/GettingStarted.md +++ b/docs/docs/GettingStarted.md @@ -166,16 +166,16 @@ try { await body.json() } catch (err) { switch (err.code) { - case errors.ConnectTimeoutError.code: + case 'UND_ERR_CONNECT_TIMEOUT': console.error('Connection timed out') break - case errors.HeadersTimeoutError.code: + case 'UND_ERR_HEADERS_TIMEOUT': console.error('Headers timed out') break - case errors.BodyTimeoutError.code: + case 'UND_ERR_BODY_TIMEOUT': console.error('Body timed out') break - case errors.RequestAbortedError.code: + case 'UND_ERR_ABORTED': console.error('Request was aborted') break default: diff --git a/docs/docs/api/BalancedPool.md b/docs/docs/api/BalancedPool.md index df267fe7270..6d80317af78 100644 --- a/docs/docs/api/BalancedPool.md +++ b/docs/docs/api/BalancedPool.md @@ -34,7 +34,7 @@ Implements [Client.closed](/docs/docs/api/Client.md#clientclosed) Implements [Client.destroyed](/docs/docs/api/Client.md#clientdestroyed) -### `Pool.stats` +### `BalancedPool.stats` Returns [`PoolStats`](/docs/docs/api/PoolStats.md) instance for this pool. diff --git a/docs/docs/api/Dispatcher.md b/docs/docs/api/Dispatcher.md index 2137e174a8a..3a9ef9c2909 100644 --- a/docs/docs/api/Dispatcher.md +++ b/docs/docs/api/Dispatcher.md @@ -211,6 +211,7 @@ Returns: `Boolean` - `false` if dispatcher is busy and further dispatch calls wo * **onResponseData** `(controller: DispatchController, chunk: Buffer) => void` - Invoked when response payload data is received. Not required for `upgrade` requests. * **onResponseEnd** `(controller: DispatchController, trailers: Record) => void` - Invoked when response payload and trailers have been received and the request has completed. Not required for `upgrade` requests. * **onResponseError** `(controller: DispatchController, error: Error) => void` - Invoked when an error has occurred. May not throw. +* **onBodySent** `(chunk: Buffer) => void` (optional) - Invoked when a chunk of the request body is sent. #### Migration from legacy handler API @@ -688,7 +689,7 @@ return null A faster version of `Dispatcher.request`. This method expects the second argument `factory` to return a [`stream.Writable`](https://nodejs.org/api/stream.html#stream_class_stream_writable) stream which the response will be written to. This improves performance by avoiding creating an intermediate [`stream.Readable`](https://nodejs.org/api/stream.html#stream_readable_streams) stream when the user expects to directly pipe the response body to a [`stream.Writable`](https://nodejs.org/api/stream.html#stream_class_stream_writable) stream. -As demonstrated in [Example 1 - Basic GET stream request](/docs/docs/api/Dispatcher.md#example-1-basic-get-stream-request), it is recommended to use the `option.opaque` property to avoid creating a closure for the `factory` method. This pattern works well with Node.js Web Frameworks such as [Fastify](https://fastify.io). See [Example 2 - Stream to Fastify Response](/docs/docs/api/Dispatch.md#example-2-stream-to-fastify-response) for more details. +As demonstrated in [Example 1 - Basic GET stream request](/docs/docs/api/Dispatcher.md#example-1-basic-get-stream-request), it is recommended to use the `option.opaque` property to avoid creating a closure for the `factory` method. This pattern works well with Node.js Web Frameworks such as [Fastify](https://fastify.io). See [Example 2 - Stream to Fastify Response](/docs/docs/api/Dispatcher.md#example-2-stream-to-fastify-response) for more details. Arguments: diff --git a/docs/docs/api/Errors.md b/docs/docs/api/Errors.md index 58e29790fe4..6a4bc3c6706 100644 --- a/docs/docs/api/Errors.md +++ b/docs/docs/api/Errors.md @@ -32,7 +32,7 @@ import { errors } from 'undici' | `ResponseError` | `UND_ERR_RESPONSE` | response returned an error status code; carries `statusCode`, `headers` and `body`. | | `MaxOriginsReachedError` | `UND_ERR_MAX_ORIGINS_REACHED` | the maximum number of allowed origins has been reached. | | `BalancedPoolMissingUpstreamError` | `UND_ERR_BPL_MISSING_UPSTREAM` | no upstream has been added to the `BalancedPool`. | -| `Socks5ProxyError` | `UND_ERR_SOCKS5*` | an error occurred during SOCKS5 proxy negotiation. | +| `Socks5ProxyError` | `UND_ERR_SOCKS5` | an error occurred during SOCKS5 proxy negotiation. | | `HTTPParserError` | `HPE_*` | an error occurred while parsing the HTTP response (extends `Error`, not `UndiciError`). | Be aware of the possible difference between the global dispatcher version and the actual undici version you might be using. We recommend to avoid the check `instanceof errors.UndiciError` and seek for the `error.code === ''` instead to avoid inconsistencies. diff --git a/docs/docs/api/MockAgent.md b/docs/docs/api/MockAgent.md index b4ce8106bb0..d46f1b95a21 100644 --- a/docs/docs/api/MockAgent.md +++ b/docs/docs/api/MockAgent.md @@ -580,7 +580,7 @@ mockAgent.getCallHistory()?.firstCall() ```js const mockAgent = new MockAgent() -mockAgent.clearAllCallHistory() +mockAgent.clearCallHistory() ``` #### Example - call history instance class method diff --git a/docs/docs/api/RetryAgent.md b/docs/docs/api/RetryAgent.md index fdf394fbad4..3dc206ce63f 100644 --- a/docs/docs/api/RetryAgent.md +++ b/docs/docs/api/RetryAgent.md @@ -12,7 +12,7 @@ Arguments: * **dispatcher** `undici.Dispatcher` (required) - the dispatcher to wrap * **options** `RetryHandlerOptions` (optional) - the options -Returns: `ProxyAgent` +Returns: `RetryAgent` ### Parameter: `RetryHandlerOptions` @@ -23,9 +23,9 @@ Returns: `ProxyAgent` - **minTimeout** `number` (optional) - Minimum number of milliseconds to wait before retrying. Default: `500` (half a second) - **timeoutFactor** `number` (optional) - Factor to multiply the timeout by for each retry attempt. Default: `2` - **retryAfter** `boolean` (optional) - It enables automatic retry after the `Retry-After` header is received. Default: `true` -- **methods** `string[]` (optional) - Array of HTTP methods to retry. Default: `['GET', 'PUT', 'HEAD', 'OPTIONS', 'DELETE']` +- **methods** `string[]` (optional) - Array of HTTP methods to retry. Default: `['GET', 'HEAD', 'OPTIONS', 'PUT', 'DELETE', 'TRACE']` - **statusCodes** `number[]` (optional) - Array of HTTP status codes to retry. Default: `[429, 500, 502, 503, 504]` -- **errorCodes** `string[]` (optional) - Array of Error codes to retry. Default: `['ECONNRESET', 'ECONNREFUSED', 'ENOTFOUND', 'ENETDOWN','ENETUNREACH', 'EHOSTDOWN', 'UND_ERR_SOCKET']` +- **errorCodes** `string[]` (optional) - Array of Error codes to retry. Default: `['ECONNRESET', 'ECONNREFUSED', 'ENOTFOUND', 'ENETDOWN', 'ENETUNREACH', 'EHOSTDOWN', 'EHOSTUNREACH', 'EPIPE', 'UND_ERR_SOCKET']` **`RetryContext`** diff --git a/docs/docs/api/RetryHandler.md b/docs/docs/api/RetryHandler.md index 07e7a2dac33..23c91a61af6 100644 --- a/docs/docs/api/RetryHandler.md +++ b/docs/docs/api/RetryHandler.md @@ -4,12 +4,12 @@ Extends: `undici.DispatcherHandlers` A handler class that implements the retry logic for a request. -## `new RetryHandler(dispatchOptions, retryHandlers, [retryOptions])` +## `new RetryHandler(opts, { dispatch, handler })` Arguments: -- **options** `Dispatch.DispatchOptions & RetryOptions` (required) - It is an intersection of `Dispatcher.DispatchOptions` and `RetryOptions`. -- **retryHandlers** `RetryHandlers` (required) - Object containing the `dispatch` to be used on every retry, and `handler` for handling the `dispatch` lifecycle. +- **opts** `Dispatch.DispatchOptions & { retryOptions?: RetryOptions }` (required) - An intersection of `Dispatcher.DispatchOptions` and an optional `RetryOptions` object. +- **{ dispatch, handler }** `RetryHandlers` (required) - Object containing the `dispatch` to be used on every retry, and `handler` for handling the `dispatch` lifecycle. Returns: `retryHandler` @@ -26,9 +26,9 @@ Extends: [`Dispatch.DispatchOptions`](/docs/docs/api/Dispatcher.md#parameter-dis - **minTimeout** `number` (optional) - Minimum number of milliseconds to wait before retrying. Default: `500` (half a second) - **timeoutFactor** `number` (optional) - Factor to multiply the timeout by for each retry attempt. Default: `2` - **retryAfter** `boolean` (optional) - It enables automatic retry after the `Retry-After` header is received. Default: `true` -- **methods** `string[]` (optional) - Array of HTTP methods to retry. Default: `['GET', 'PUT', 'HEAD', 'OPTIONS', 'DELETE']` +- **methods** `string[]` (optional) - Array of HTTP methods to retry. Default: `['GET', 'HEAD', 'OPTIONS', 'PUT', 'DELETE', 'TRACE']` - **statusCodes** `number[]` (optional) - Array of HTTP status codes to retry. Default: `[429, 500, 502, 503, 504]` -- **errorCodes** `string[]` (optional) - Array of Error codes to retry. Default: `['ECONNRESET', 'ECONNREFUSED', 'ENOTFOUND', 'ENETDOWN','ENETUNREACH', 'EHOSTDOWN', 'UND_ERR_SOCKET']` +- **errorCodes** `string[]` (optional) - Array of Error codes to retry. Default: `['ECONNRESET', 'ECONNREFUSED', 'ENOTFOUND', 'ENETDOWN', 'ENETUNREACH', 'EHOSTDOWN', 'EHOSTUNREACH', 'EPIPE', 'UND_ERR_SOCKET']` **`RetryContext`**