Back to Node

Errors

deps/undici/src/docs/docs/api/Errors.md

26.3.03.9 KB
Original Source

Errors

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.

js
import { errors } from 'undici'
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

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.

SocketError

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

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