undici exposes a set of typed error classes accessible via theDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/nodejs/undici/llms.txt
Use this file to discover all available pages before exploring further.
errors export. Each error has a code property with a stable string identifier. Use error.code checks rather than instanceof to reliably identify undici errors â this avoids version mismatch issues when Node.jsâs bundled undici differs from the installed version.
Importing
Error reference
| Error Class | Code | Description |
|---|---|---|
UndiciError | UND_ERR | Base class for all undici errors |
ConnectTimeoutError | UND_ERR_CONNECT_TIMEOUT | Socket destroyed due to connect timeout |
HeadersTimeoutError | UND_ERR_HEADERS_TIMEOUT | Socket destroyed due to headers timeout |
HeadersOverflowError | UND_ERR_HEADERS_OVERFLOW | Socket destroyed due to headers exceeding max size |
BodyTimeoutError | UND_ERR_BODY_TIMEOUT | Socket destroyed due to body timeout |
InvalidArgumentError | UND_ERR_INVALID_ARG | An invalid argument was passed |
InvalidReturnValueError | UND_ERR_INVALID_RETURN_VALUE | A callback or factory returned an invalid value |
RequestAbortedError | UND_ERR_ABORTED | The request was aborted via AbortSignal |
ClientDestroyedError | UND_ERR_DESTROYED | Attempt to use a destroyed client |
ClientClosedError | UND_ERR_CLOSED | Attempt to use a closed client |
SocketError | UND_ERR_SOCKET | A socket-level error occurred |
NotSupportedError | UND_ERR_NOT_SUPPORTED | Unsupported functionality was used |
RequestContentLengthMismatchError | UND_ERR_REQ_CONTENT_LENGTH_MISMATCH | Request body size doesnât match Content-Length header |
ResponseContentLengthMismatchError | UND_ERR_RES_CONTENT_LENGTH_MISMATCH | Response body size doesnât match Content-Length header |
InformationalError | UND_ERR_INFO | Expected error with informational reason |
ResponseExceededMaxSizeError | UND_ERR_RES_EXCEEDED_MAX_SIZE | Response body exceeded maxResponseSize limit |
SecureProxyConnectionError | UND_ERR_PRX_TLS | TLS connection to a proxy server failed |
MessageSizeExceededError | UND_ERR_WS_MESSAGE_SIZE_EXCEEDED | WebSocket decompressed message exceeded maximum size |
SocketError
SocketError includes a .socket property with metadata about the connection:
Handling SocketError
The
.socket property may be null in some error scenarios even when the error code is UND_ERR_SOCKET.Timeout errors
Configure timeouts onClient, Pool, or Agent to control when these errors are thrown:
Configuring timeouts
Abort errors
UseAbortController to cancel requests, which throws RequestAbortedError:
Aborting requests
Handling errors comprehensively
Comprehensive error handling