-
-
Notifications
You must be signed in to change notification settings - Fork 957
/
Copy path8-errors.md
106 lines (59 loc) · 2.75 KB
/
8-errors.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
[> Back to homepage](../readme.md#documentation)
## Errors
Source code:
- [`source/core/errors.ts`](../source/core/errors.ts)
- [`source/as-promise/types.ts`](../source/as-promise/types.ts)
- [`source/core/response.ts`](../source/core/response.ts)
All Got errors contain various metadata, such as:
- `code` - A string like `ERR_NON_2XX_3XX_RESPONSE`,
- `options` - An instance of [`Options`](2-options.md),
- `request` - An instance of Got Stream,
- `response` (optional) - An instance of Got Response,
- `timings` (optional) - Points to `response.timings`.
#### Capturing async stack traces
Read the article [here](async-stack-traces.md).
> [!NOTE]
> - The error codes may differ when the root error has a `code` property set.
> - The root error will be propagated as is via the [`cause`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/cause) property.
### `RequestError`
**Code: `ERR_GOT_REQUEST_ERROR`**
When a request fails. Contains a `code` property with error class code, like `ECONNREFUSED`. All the errors below inherit this one.
### `CacheError`
**Code: `ERR_CACHE_ACCESS`**
When a cache method fails, for example, if the database goes down or there's a filesystem error.
### `ReadError`
**Code: `ERR_READING_RESPONSE_STREAM`**
When reading from response stream fails.
### `ParseError`
**Code: `ERR_BODY_PARSE_FAILURE`**
When server response code is 2xx, and parsing body fails. Includes a `response` property.
### `UploadError`
**Code: `ERR_UPLOAD`**
When the request body is a stream and an error occurs while reading from that stream.
### `HTTPError`
**Code: `ERR_NON_2XX_3XX_RESPONSE`**
When the request is unsuccessful.
A request is successful when the status code of the final request is `2xx` or `3xx`.
When [following redirects](2-options.md#followredirect), a request is successful **only** when the status code of the final request is `2xx`.
> [!NOTE]
> `304` responses are always considered successful.
### `MaxRedirectsError`
**Code: `ERR_TOO_MANY_REDIRECTS`**
When the server redirects you more than ten times. Includes a `response` property.
### `UnsupportedProtocolError`
> [!NOTE]
> This error is not public.
**Code: `ERR_UNSUPPORTED_PROTOCOL`**
When given an unsupported protocol.
### `TimeoutError`
**Code: `ETIMEDOUT`**
When the request is aborted due to a [timeout](6-timeout.md). Includes an `event` (a string) property along with `timings`.
### `CancelError`
**Code: `ERR_CANCELED`**
When the request is aborted with `promise.cancel()`.
### `RetryError`
**Code: `ERR_RETRYING`**
Always triggers a new retry when thrown.
### `AbortError`
**Code: `ERR_ABORTED`**
When the request is aborted with [AbortController.abort()](https://developer.mozilla.org/en-US/docs/Web/API/AbortController/abort).