On this page

Undici exposes a variety of error objects that you can use to enhance your error handling. You can find all the error objects inside the errors key.

ErrorError CodesDescription
UndiciErrorUND_ERRall errors below are extended from UndiciError.
ConnectTimeoutErrorUND_ERR_CONNECT_TIMEOUTsocket is destroyed due to connect timeout.
HeadersTimeoutErrorUND_ERR_HEADERS_TIMEOUTsocket is destroyed due to headers timeout.
HeadersOverflowErrorUND_ERR_HEADERS_OVERFLOWsocket is destroyed due to headers' max size being exceeded.
BodyTimeoutErrorUND_ERR_BODY_TIMEOUTsocket is destroyed due to body timeout.
InvalidArgumentErrorUND_ERR_INVALID_ARGpassed an invalid argument.
InvalidReturnValueErrorUND_ERR_INVALID_RETURN_VALUEreturned an invalid value.
RequestAbortedErrorUND_ERR_ABORTEDthe request has been aborted by the user
ClientDestroyedErrorUND_ERR_DESTROYEDtrying to use a destroyed client.
ClientClosedErrorUND_ERR_CLOSEDtrying to use a closed client.
SocketErrorUND_ERR_SOCKETthere is an error with the socket.
NotSupportedErrorUND_ERR_NOT_SUPPORTEDencountered unsupported functionality.
RequestContentLengthMismatchErrorUND_ERR_REQ_CONTENT_LENGTH_MISMATCHrequest body does not match content-length header
ResponseContentLengthMismatchErrorUND_ERR_RES_CONTENT_LENGTH_MISMATCHresponse body does not match content-length header
InformationalErrorUND_ERR_INFOexpected error with reason
ResponseExceededMaxSizeErrorUND_ERR_RES_EXCEEDED_MAX_SIZEresponse body exceed the max size allowed
SecureProxyConnectionErrorUND_ERR_PRX_TLStls connection to a proxy failed
MessageSizeExceededErrorUND_ERR_WS_MESSAGE_SIZE_EXCEEDEDWebSocket decompressed message exceeded the maximum allowed size
AbortErrorUND_ERR_ABORTthe operation was aborted (base class of RequestAbortedError).
RequestRetryErrorUND_ERR_REQ_RETRYrequest failed and could not be retried; carries statusCode, headers and data.
ResponseErrorUND_ERR_RESPONSEresponse returned an error status code; carries statusCode, headers and body.
MaxOriginsReachedErrorUND_ERR_MAX_ORIGINS_REACHEDthe maximum number of allowed origins has been reached.
BalancedPoolMissingUpstreamErrorUND_ERR_BPL_MISSING_UPSTREAMno upstream has been added to the BalancedPool.
Socks5ProxyErrorUND_ERR_SOCKS5an error occurred during SOCKS5 proxy negotiation.
HTTPParserErrorHPE_*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 === '<error_code>' instead to avoid inconsistencies.

When autoSelectFamily is enabled and every attempted address fails with a timeout, Node raises an AggregateError. Undici surfaces these multi-address timeouts as ConnectTimeoutError (so the error shape is the same regardless of whether Node's family-attempt timer or undici's connectTimeout wins the race); the original AggregateError is preserved on error.cause.

The SocketError has a .socket property which holds socket metadata:

interface SocketInfo {
  localAddress?: string
  localPort?: number
  remoteAddress?: string
  remotePort?: number
  remoteFamily?: string
  timeout?: number
  bytesWritten?: number
  bytesRead?: number
}

Be aware that in some cases the .socket property can be null.