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