1 | # Errors
|
---|
2 |
|
---|
3 | Undici exposes a variety of error objects that you can use to enhance your error handling.
|
---|
4 | You can find all the error objects inside the `errors` key.
|
---|
5 |
|
---|
6 | ```js
|
---|
7 | import { errors } from 'undici'
|
---|
8 | ```
|
---|
9 |
|
---|
10 | | Error | Error Codes | Description |
|
---|
11 | | ------------------------------------ | ------------------------------------- | ------------------------------------------------------------------------- |
|
---|
12 | | `UndiciError` | `UND_ERR` | all errors below are extended from `UndiciError`. |
|
---|
13 | | `ConnectTimeoutError` | `UND_ERR_CONNECT_TIMEOUT` | socket is destroyed due to connect timeout. |
|
---|
14 | | `HeadersTimeoutError` | `UND_ERR_HEADERS_TIMEOUT` | socket is destroyed due to headers timeout. |
|
---|
15 | | `HeadersOverflowError` | `UND_ERR_HEADERS_OVERFLOW` | socket is destroyed due to headers' max size being exceeded. |
|
---|
16 | | `BodyTimeoutError` | `UND_ERR_BODY_TIMEOUT` | socket is destroyed due to body timeout. |
|
---|
17 | | `ResponseStatusCodeError` | `UND_ERR_RESPONSE_STATUS_CODE` | an error is thrown when `throwOnError` is `true` for status codes >= 400. |
|
---|
18 | | `InvalidArgumentError` | `UND_ERR_INVALID_ARG` | passed an invalid argument. |
|
---|
19 | | `InvalidReturnValueError` | `UND_ERR_INVALID_RETURN_VALUE` | returned an invalid value. |
|
---|
20 | | `RequestAbortedError` | `UND_ERR_ABORTED` | the request has been aborted by the user |
|
---|
21 | | `ClientDestroyedError` | `UND_ERR_DESTROYED` | trying to use a destroyed client. |
|
---|
22 | | `ClientClosedError` | `UND_ERR_CLOSED` | trying to use a closed client. |
|
---|
23 | | `SocketError` | `UND_ERR_SOCKET` | there is an error with the socket. |
|
---|
24 | | `NotSupportedError` | `UND_ERR_NOT_SUPPORTED` | encountered unsupported functionality. |
|
---|
25 | | `RequestContentLengthMismatchError` | `UND_ERR_REQ_CONTENT_LENGTH_MISMATCH` | request body does not match content-length header |
|
---|
26 | | `ResponseContentLengthMismatchError` | `UND_ERR_RES_CONTENT_LENGTH_MISMATCH` | response body does not match content-length header |
|
---|
27 | | `InformationalError` | `UND_ERR_INFO` | expected error with reason |
|
---|
28 | | `ResponseExceededMaxSizeError` | `UND_ERR_RES_EXCEEDED_MAX_SIZE` | response body exceed the max size allowed |
|
---|
29 |
|
---|
30 | ### `SocketError`
|
---|
31 |
|
---|
32 | The `SocketError` has a `.socket` property which holds socket metadata:
|
---|
33 |
|
---|
34 | ```ts
|
---|
35 | interface SocketInfo {
|
---|
36 | localAddress?: string
|
---|
37 | localPort?: number
|
---|
38 | remoteAddress?: string
|
---|
39 | remotePort?: number
|
---|
40 | remoteFamily?: string
|
---|
41 | timeout?: number
|
---|
42 | bytesWritten?: number
|
---|
43 | bytesRead?: number
|
---|
44 | }
|
---|
45 | ```
|
---|
46 |
|
---|
47 | Be aware that in some cases the `.socket` property can be `null`.
|
---|