|
1 | 1 | 'use strict' |
2 | 2 |
|
| 3 | +const kUndiciError = Symbol.for('undici.error.UND_ERR') |
3 | 4 | class UndiciError extends Error { |
4 | 5 | constructor (message) { |
5 | 6 | super(message) |
6 | 7 | this.name = 'UndiciError' |
7 | 8 | this.code = 'UND_ERR' |
8 | 9 | } |
| 10 | + |
| 11 | + static [Symbol.hasInstance] (instance) { |
| 12 | + return instance && instance[kUndiciError] === true |
| 13 | + } |
| 14 | + |
| 15 | + [kUndiciError] = true |
9 | 16 | } |
10 | 17 |
|
| 18 | +const kConnectTimeoutError = Symbol.for('undici.error.UND_ERR_CONNECT_TIMEOUT') |
11 | 19 | class ConnectTimeoutError extends UndiciError { |
12 | 20 | constructor (message) { |
13 | 21 | super(message) |
14 | 22 | this.name = 'ConnectTimeoutError' |
15 | 23 | this.message = message || 'Connect Timeout Error' |
16 | 24 | this.code = 'UND_ERR_CONNECT_TIMEOUT' |
17 | 25 | } |
| 26 | + |
| 27 | + static [Symbol.hasInstance] (instance) { |
| 28 | + return instance && instance[kConnectTimeoutError] === true |
| 29 | + } |
| 30 | + |
| 31 | + [kConnectTimeoutError] = true |
18 | 32 | } |
19 | 33 |
|
| 34 | +const kHeadersTimeoutError = Symbol.for('undici.error.UND_ERR_HEADERS_TIMEOUT') |
20 | 35 | class HeadersTimeoutError extends UndiciError { |
21 | 36 | constructor (message) { |
22 | 37 | super(message) |
23 | 38 | this.name = 'HeadersTimeoutError' |
24 | 39 | this.message = message || 'Headers Timeout Error' |
25 | 40 | this.code = 'UND_ERR_HEADERS_TIMEOUT' |
26 | 41 | } |
| 42 | + |
| 43 | + static [Symbol.hasInstance] (instance) { |
| 44 | + return instance && instance[kHeadersTimeoutError] === true |
| 45 | + } |
| 46 | + |
| 47 | + [kHeadersTimeoutError] = true |
27 | 48 | } |
28 | 49 |
|
| 50 | +const kHeadersOverflowError = Symbol.for('undici.error.UND_ERR_HEADERS_OVERFLOW') |
29 | 51 | class HeadersOverflowError extends UndiciError { |
30 | 52 | constructor (message) { |
31 | 53 | super(message) |
32 | 54 | this.name = 'HeadersOverflowError' |
33 | 55 | this.message = message || 'Headers Overflow Error' |
34 | 56 | this.code = 'UND_ERR_HEADERS_OVERFLOW' |
35 | 57 | } |
| 58 | + |
| 59 | + static [Symbol.hasInstance] (instance) { |
| 60 | + return instance && instance[kHeadersOverflowError] === true |
| 61 | + } |
| 62 | + |
| 63 | + [kHeadersOverflowError] = true |
36 | 64 | } |
37 | 65 |
|
| 66 | +const kBodyTimeoutError = Symbol.for('undici.error.UND_ERR_BODY_TIMEOUT') |
38 | 67 | class BodyTimeoutError extends UndiciError { |
39 | 68 | constructor (message) { |
40 | 69 | super(message) |
41 | 70 | this.name = 'BodyTimeoutError' |
42 | 71 | this.message = message || 'Body Timeout Error' |
43 | 72 | this.code = 'UND_ERR_BODY_TIMEOUT' |
44 | 73 | } |
| 74 | + |
| 75 | + static [Symbol.hasInstance] (instance) { |
| 76 | + return instance && instance[kBodyTimeoutError] === true |
| 77 | + } |
| 78 | + |
| 79 | + [kBodyTimeoutError] = true |
45 | 80 | } |
46 | 81 |
|
| 82 | +const kResponseStatusCodeError = Symbol.for('undici.error.UND_ERR_RESPONSE_STATUS_CODE') |
47 | 83 | class ResponseStatusCodeError extends UndiciError { |
48 | 84 | constructor (message, statusCode, headers, body) { |
49 | 85 | super(message) |
@@ -55,88 +91,159 @@ class ResponseStatusCodeError extends UndiciError { |
55 | 91 | this.statusCode = statusCode |
56 | 92 | this.headers = headers |
57 | 93 | } |
| 94 | + |
| 95 | + static [Symbol.hasInstance] (instance) { |
| 96 | + return instance && instance[kResponseStatusCodeError] === true |
| 97 | + } |
| 98 | + |
| 99 | + [kResponseStatusCodeError] = true |
58 | 100 | } |
59 | 101 |
|
| 102 | +const kInvalidArgumentError = Symbol.for('undici.error.UND_ERR_INVALID_ARG') |
60 | 103 | class InvalidArgumentError extends UndiciError { |
61 | 104 | constructor (message) { |
62 | 105 | super(message) |
63 | 106 | this.name = 'InvalidArgumentError' |
64 | 107 | this.message = message || 'Invalid Argument Error' |
65 | 108 | this.code = 'UND_ERR_INVALID_ARG' |
66 | 109 | } |
| 110 | + |
| 111 | + static [Symbol.hasInstance] (instance) { |
| 112 | + return instance && instance[kInvalidArgumentError] === true |
| 113 | + } |
| 114 | + |
| 115 | + [kInvalidArgumentError] = true |
67 | 116 | } |
68 | 117 |
|
| 118 | +const kInvalidReturnValueError = Symbol.for('undici.error.UND_ERR_INVALID_RETURN_VALUE') |
69 | 119 | class InvalidReturnValueError extends UndiciError { |
70 | 120 | constructor (message) { |
71 | 121 | super(message) |
72 | 122 | this.name = 'InvalidReturnValueError' |
73 | 123 | this.message = message || 'Invalid Return Value Error' |
74 | 124 | this.code = 'UND_ERR_INVALID_RETURN_VALUE' |
75 | 125 | } |
| 126 | + |
| 127 | + static [Symbol.hasInstance] (instance) { |
| 128 | + return instance && instance[kInvalidReturnValueError] === true |
| 129 | + } |
| 130 | + |
| 131 | + [kInvalidReturnValueError] = true |
76 | 132 | } |
77 | 133 |
|
| 134 | +const kAbortError = Symbol.for('undici.error.UND_ERR_ABORT') |
78 | 135 | class AbortError extends UndiciError { |
79 | 136 | constructor (message) { |
80 | 137 | super(message) |
81 | 138 | this.name = 'AbortError' |
82 | 139 | this.message = message || 'The operation was aborted' |
| 140 | + this.code = 'UND_ERR_ABORT' |
| 141 | + } |
| 142 | + |
| 143 | + static [Symbol.hasInstance] (instance) { |
| 144 | + return instance && instance[kAbortError] === true |
83 | 145 | } |
| 146 | + |
| 147 | + [kAbortError] = true |
84 | 148 | } |
85 | 149 |
|
| 150 | +const kRequestAbortedError = Symbol.for('undici.error.UND_ERR_ABORTED') |
86 | 151 | class RequestAbortedError extends AbortError { |
87 | 152 | constructor (message) { |
88 | 153 | super(message) |
89 | 154 | this.name = 'AbortError' |
90 | 155 | this.message = message || 'Request aborted' |
91 | 156 | this.code = 'UND_ERR_ABORTED' |
92 | 157 | } |
| 158 | + |
| 159 | + static [Symbol.hasInstance] (instance) { |
| 160 | + return instance && instance[kRequestAbortedError] === true |
| 161 | + } |
| 162 | + |
| 163 | + [kRequestAbortedError] = true |
93 | 164 | } |
94 | 165 |
|
| 166 | +const kInformationalError = Symbol.for('undici.error.UND_ERR_INFO') |
95 | 167 | class InformationalError extends UndiciError { |
96 | 168 | constructor (message) { |
97 | 169 | super(message) |
98 | 170 | this.name = 'InformationalError' |
99 | 171 | this.message = message || 'Request information' |
100 | 172 | this.code = 'UND_ERR_INFO' |
101 | 173 | } |
| 174 | + |
| 175 | + static [Symbol.hasInstance] (instance) { |
| 176 | + return instance && instance[kInformationalError] === true |
| 177 | + } |
| 178 | + |
| 179 | + [kInformationalError] = true |
102 | 180 | } |
103 | 181 |
|
| 182 | +const kRequestContentLengthMismatchError = Symbol.for('undici.error.UND_ERR_REQ_CONTENT_LENGTH_MISMATCH') |
104 | 183 | class RequestContentLengthMismatchError extends UndiciError { |
105 | 184 | constructor (message) { |
106 | 185 | super(message) |
107 | 186 | this.name = 'RequestContentLengthMismatchError' |
108 | 187 | this.message = message || 'Request body length does not match content-length header' |
109 | 188 | this.code = 'UND_ERR_REQ_CONTENT_LENGTH_MISMATCH' |
110 | 189 | } |
| 190 | + |
| 191 | + static [Symbol.hasInstance] (instance) { |
| 192 | + return instance && instance[kRequestContentLengthMismatchError] === true |
| 193 | + } |
| 194 | + |
| 195 | + [kRequestContentLengthMismatchError] = true |
111 | 196 | } |
112 | 197 |
|
| 198 | +const kResponseContentLengthMismatchError = Symbol.for('undici.error.UND_ERR_RES_CONTENT_LENGTH_MISMATCH') |
113 | 199 | class ResponseContentLengthMismatchError extends UndiciError { |
114 | 200 | constructor (message) { |
115 | 201 | super(message) |
116 | 202 | this.name = 'ResponseContentLengthMismatchError' |
117 | 203 | this.message = message || 'Response body length does not match content-length header' |
118 | 204 | this.code = 'UND_ERR_RES_CONTENT_LENGTH_MISMATCH' |
119 | 205 | } |
| 206 | + |
| 207 | + static [Symbol.hasInstance] (instance) { |
| 208 | + return instance && instance[kResponseContentLengthMismatchError] === true |
| 209 | + } |
| 210 | + |
| 211 | + [kResponseContentLengthMismatchError] = true |
120 | 212 | } |
121 | 213 |
|
| 214 | +const kClientDestroyedError = Symbol.for('undici.error.UND_ERR_DESTROYED') |
122 | 215 | class ClientDestroyedError extends UndiciError { |
123 | 216 | constructor (message) { |
124 | 217 | super(message) |
125 | 218 | this.name = 'ClientDestroyedError' |
126 | 219 | this.message = message || 'The client is destroyed' |
127 | 220 | this.code = 'UND_ERR_DESTROYED' |
128 | 221 | } |
| 222 | + |
| 223 | + static [Symbol.hasInstance] (instance) { |
| 224 | + return instance && instance[kClientDestroyedError] === true |
| 225 | + } |
| 226 | + |
| 227 | + [kClientDestroyedError] = true |
129 | 228 | } |
130 | 229 |
|
| 230 | +const kClientClosedError = Symbol.for('undici.error.UND_ERR_CLOSED') |
131 | 231 | class ClientClosedError extends UndiciError { |
132 | 232 | constructor (message) { |
133 | 233 | super(message) |
134 | 234 | this.name = 'ClientClosedError' |
135 | 235 | this.message = message || 'The client is closed' |
136 | 236 | this.code = 'UND_ERR_CLOSED' |
137 | 237 | } |
| 238 | + |
| 239 | + static [Symbol.hasInstance] (instance) { |
| 240 | + return instance && instance[kClientClosedError] === true |
| 241 | + } |
| 242 | + |
| 243 | + [kClientClosedError] = true |
138 | 244 | } |
139 | 245 |
|
| 246 | +const kSocketError = Symbol.for('undici.error.UND_ERR_SOCKET') |
140 | 247 | class SocketError extends UndiciError { |
141 | 248 | constructor (message, socket) { |
142 | 249 | super(message) |
@@ -145,44 +252,79 @@ class SocketError extends UndiciError { |
145 | 252 | this.code = 'UND_ERR_SOCKET' |
146 | 253 | this.socket = socket |
147 | 254 | } |
| 255 | + |
| 256 | + static [Symbol.hasInstance] (instance) { |
| 257 | + return instance && instance[kSocketError] === true |
| 258 | + } |
| 259 | + |
| 260 | + [kSocketError] = true |
148 | 261 | } |
149 | 262 |
|
| 263 | +const kNotSupportedError = Symbol.for('undici.error.UND_ERR_NOT_SUPPORTED') |
150 | 264 | class NotSupportedError extends UndiciError { |
151 | 265 | constructor (message) { |
152 | 266 | super(message) |
153 | 267 | this.name = 'NotSupportedError' |
154 | 268 | this.message = message || 'Not supported error' |
155 | 269 | this.code = 'UND_ERR_NOT_SUPPORTED' |
156 | 270 | } |
| 271 | + |
| 272 | + static [Symbol.hasInstance] (instance) { |
| 273 | + return instance && instance[kNotSupportedError] === true |
| 274 | + } |
| 275 | + |
| 276 | + [kNotSupportedError] = true |
157 | 277 | } |
158 | 278 |
|
| 279 | +const kBalancedPoolMissingUpstreamError = Symbol.for('undici.error.UND_ERR_BPL_MISSING_UPSTREAM') |
159 | 280 | class BalancedPoolMissingUpstreamError extends UndiciError { |
160 | 281 | constructor (message) { |
161 | 282 | super(message) |
162 | 283 | this.name = 'MissingUpstreamError' |
163 | 284 | this.message = message || 'No upstream has been added to the BalancedPool' |
164 | 285 | this.code = 'UND_ERR_BPL_MISSING_UPSTREAM' |
165 | 286 | } |
| 287 | + |
| 288 | + static [Symbol.hasInstance] (instance) { |
| 289 | + return instance && instance[kBalancedPoolMissingUpstreamError] === true |
| 290 | + } |
| 291 | + |
| 292 | + [kBalancedPoolMissingUpstreamError] = true |
166 | 293 | } |
167 | 294 |
|
| 295 | +const kHTTPParserError = Symbol.for('undici.error.UND_ERR_HTTP_PARSER') |
168 | 296 | class HTTPParserError extends Error { |
169 | 297 | constructor (message, code, data) { |
170 | 298 | super(message) |
171 | 299 | this.name = 'HTTPParserError' |
172 | 300 | this.code = code ? `HPE_${code}` : undefined |
173 | 301 | this.data = data ? data.toString() : undefined |
174 | 302 | } |
| 303 | + |
| 304 | + static [Symbol.hasInstance] (instance) { |
| 305 | + return instance && instance[kHTTPParserError] === true |
| 306 | + } |
| 307 | + |
| 308 | + [kHTTPParserError] = true |
175 | 309 | } |
176 | 310 |
|
| 311 | +const kResponseExceededMaxSizeError = Symbol.for('undici.error.UND_ERR_RES_EXCEEDED_MAX_SIZE') |
177 | 312 | class ResponseExceededMaxSizeError extends UndiciError { |
178 | 313 | constructor (message) { |
179 | 314 | super(message) |
180 | 315 | this.name = 'ResponseExceededMaxSizeError' |
181 | 316 | this.message = message || 'Response content exceeded max size' |
182 | 317 | this.code = 'UND_ERR_RES_EXCEEDED_MAX_SIZE' |
183 | 318 | } |
| 319 | + |
| 320 | + static [Symbol.hasInstance] (instance) { |
| 321 | + return instance && instance[kResponseExceededMaxSizeError] === true |
| 322 | + } |
| 323 | + |
| 324 | + [kResponseExceededMaxSizeError] = true |
184 | 325 | } |
185 | 326 |
|
| 327 | +const kRequestRetryError = Symbol.for('undici.error.UND_ERR_REQ_RETRY') |
186 | 328 | class RequestRetryError extends UndiciError { |
187 | 329 | constructor (message, code, { headers, data }) { |
188 | 330 | super(message) |
@@ -193,8 +335,15 @@ class RequestRetryError extends UndiciError { |
193 | 335 | this.data = data |
194 | 336 | this.headers = headers |
195 | 337 | } |
| 338 | + |
| 339 | + static [Symbol.hasInstance] (instance) { |
| 340 | + return instance && instance[kRequestRetryError] === true |
| 341 | + } |
| 342 | + |
| 343 | + [kRequestRetryError] = true |
196 | 344 | } |
197 | 345 |
|
| 346 | +const kResponseError = Symbol.for('undici.error.UND_ERR_RESPONSE') |
198 | 347 | class ResponseError extends UndiciError { |
199 | 348 | constructor (message, code, { headers, data }) { |
200 | 349 | super(message) |
@@ -205,8 +354,15 @@ class ResponseError extends UndiciError { |
205 | 354 | this.data = data |
206 | 355 | this.headers = headers |
207 | 356 | } |
| 357 | + |
| 358 | + static [Symbol.hasInstance] (instance) { |
| 359 | + return instance && instance[kResponseError] === true |
| 360 | + } |
| 361 | + |
| 362 | + [kResponseError] = true |
208 | 363 | } |
209 | 364 |
|
| 365 | +const kSecureProxyConnectionError = Symbol.for('undici.error.UND_ERR_PRX_TLS') |
210 | 366 | class SecureProxyConnectionError extends UndiciError { |
211 | 367 | constructor (cause, message, options) { |
212 | 368 | super(message, { cause, ...(options ?? {}) }) |
@@ -215,6 +371,12 @@ class SecureProxyConnectionError extends UndiciError { |
215 | 371 | this.code = 'UND_ERR_PRX_TLS' |
216 | 372 | this.cause = cause |
217 | 373 | } |
| 374 | + |
| 375 | + static [Symbol.hasInstance] (instance) { |
| 376 | + return instance && instance[kSecureProxyConnectionError] === true |
| 377 | + } |
| 378 | + |
| 379 | + [kSecureProxyConnectionError] = true |
218 | 380 | } |
219 | 381 |
|
220 | 382 | module.exports = { |
|