fourohfour 1.0.0-test → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,599 @@
1
+ /**
2
+ * Status code constants and reason phrases.
3
+ *
4
+ * Plain object literals with literal types, so `Status.OK` is the type `200`
5
+ * and bundlers can drop whatever you do not import.
6
+ */
7
+ /**
8
+ * IANA-registered HTTP status codes, named after their RFC 9110 reason phrase.
9
+ *
10
+ * ```ts
11
+ * Status.NOT_FOUND // 404 (type: 404)
12
+ * Status.CONTENT_TOO_LARGE // 413
13
+ * ```
14
+ *
15
+ * A few legacy names (`UNPROCESSABLE_ENTITY`, `PAYLOAD_TOO_LARGE`, ...) are kept as
16
+ * deprecated aliases so code written for other packages keeps working.
17
+ * Non-standard codes (418, 499, Cloudflare 52x, ...) live in {@link Unofficial}.
18
+ */
19
+ declare const Status: {
20
+ /** 100 Continue (RFC 9110) */
21
+ readonly CONTINUE: 100;
22
+ /** 101 Switching Protocols (RFC 9110) */
23
+ readonly SWITCHING_PROTOCOLS: 101;
24
+ /** 102 Processing (RFC 2518, WebDAV) */
25
+ readonly PROCESSING: 102;
26
+ /** 103 Early Hints (RFC 8297) */
27
+ readonly EARLY_HINTS: 103;
28
+ /** 200 OK (RFC 9110) */
29
+ readonly OK: 200;
30
+ /** 201 Created (RFC 9110) */
31
+ readonly CREATED: 201;
32
+ /** 202 Accepted (RFC 9110) */
33
+ readonly ACCEPTED: 202;
34
+ /** 203 Non-Authoritative Information (RFC 9110) */
35
+ readonly NON_AUTHORITATIVE_INFORMATION: 203;
36
+ /** 204 No Content (RFC 9110) */
37
+ readonly NO_CONTENT: 204;
38
+ /** 205 Reset Content (RFC 9110) */
39
+ readonly RESET_CONTENT: 205;
40
+ /** 206 Partial Content (RFC 9110) */
41
+ readonly PARTIAL_CONTENT: 206;
42
+ /** 207 Multi-Status (RFC 4918, WebDAV) */
43
+ readonly MULTI_STATUS: 207;
44
+ /** 208 Already Reported (RFC 5842, WebDAV) */
45
+ readonly ALREADY_REPORTED: 208;
46
+ /** 226 IM Used (RFC 3229) */
47
+ readonly IM_USED: 226;
48
+ /** 300 Multiple Choices (RFC 9110) */
49
+ readonly MULTIPLE_CHOICES: 300;
50
+ /** 301 Moved Permanently (RFC 9110). Clients may change POST to GET; use 308 to keep the method. */
51
+ readonly MOVED_PERMANENTLY: 301;
52
+ /** 302 Found (RFC 9110). Clients may change POST to GET; use 307 to keep the method. */
53
+ readonly FOUND: 302;
54
+ /** 303 See Other (RFC 9110) */
55
+ readonly SEE_OTHER: 303;
56
+ /** 304 Not Modified (RFC 9110) */
57
+ readonly NOT_MODIFIED: 304;
58
+ /** 305 Use Proxy (RFC 9110). @deprecated Deprecated by RFC 7231; clients ignore it. */
59
+ readonly USE_PROXY: 305;
60
+ /** 307 Temporary Redirect (RFC 9110) */
61
+ readonly TEMPORARY_REDIRECT: 307;
62
+ /** 308 Permanent Redirect (RFC 9110) */
63
+ readonly PERMANENT_REDIRECT: 308;
64
+ /** 400 Bad Request (RFC 9110) */
65
+ readonly BAD_REQUEST: 400;
66
+ /** 401 Unauthorized (RFC 9110). Means "unauthenticated"; send a `WWW-Authenticate` header. */
67
+ readonly UNAUTHORIZED: 401;
68
+ /** 402 Payment Required (RFC 9110) */
69
+ readonly PAYMENT_REQUIRED: 402;
70
+ /** 403 Forbidden (RFC 9110) */
71
+ readonly FORBIDDEN: 403;
72
+ /** 404 Not Found (RFC 9110) */
73
+ readonly NOT_FOUND: 404;
74
+ /** 405 Method Not Allowed (RFC 9110). Send an `Allow` header. */
75
+ readonly METHOD_NOT_ALLOWED: 405;
76
+ /** 406 Not Acceptable (RFC 9110) */
77
+ readonly NOT_ACCEPTABLE: 406;
78
+ /** 407 Proxy Authentication Required (RFC 9110) */
79
+ readonly PROXY_AUTHENTICATION_REQUIRED: 407;
80
+ /** 408 Request Timeout (RFC 9110) */
81
+ readonly REQUEST_TIMEOUT: 408;
82
+ /** 409 Conflict (RFC 9110) */
83
+ readonly CONFLICT: 409;
84
+ /** 410 Gone (RFC 9110) */
85
+ readonly GONE: 410;
86
+ /** 411 Length Required (RFC 9110) */
87
+ readonly LENGTH_REQUIRED: 411;
88
+ /** 412 Precondition Failed (RFC 9110) */
89
+ readonly PRECONDITION_FAILED: 412;
90
+ /** 413 Content Too Large (RFC 9110). Formerly "Payload Too Large". */
91
+ readonly CONTENT_TOO_LARGE: 413;
92
+ /** 414 URI Too Long (RFC 9110) */
93
+ readonly URI_TOO_LONG: 414;
94
+ /** 415 Unsupported Media Type (RFC 9110) */
95
+ readonly UNSUPPORTED_MEDIA_TYPE: 415;
96
+ /** 416 Range Not Satisfiable (RFC 9110) */
97
+ readonly RANGE_NOT_SATISFIABLE: 416;
98
+ /** 417 Expectation Failed (RFC 9110) */
99
+ readonly EXPECTATION_FAILED: 417;
100
+ /** 421 Misdirected Request (RFC 9110) */
101
+ readonly MISDIRECTED_REQUEST: 421;
102
+ /** 422 Unprocessable Content (RFC 9110). Formerly "Unprocessable Entity". */
103
+ readonly UNPROCESSABLE_CONTENT: 422;
104
+ /** 423 Locked (RFC 4918, WebDAV) */
105
+ readonly LOCKED: 423;
106
+ /** 424 Failed Dependency (RFC 4918, WebDAV) */
107
+ readonly FAILED_DEPENDENCY: 424;
108
+ /** 425 Too Early (RFC 8470) */
109
+ readonly TOO_EARLY: 425;
110
+ /** 426 Upgrade Required (RFC 9110) */
111
+ readonly UPGRADE_REQUIRED: 426;
112
+ /** 428 Precondition Required (RFC 6585) */
113
+ readonly PRECONDITION_REQUIRED: 428;
114
+ /** 429 Too Many Requests (RFC 6585). Consider a `Retry-After` header. */
115
+ readonly TOO_MANY_REQUESTS: 429;
116
+ /** 431 Request Header Fields Too Large (RFC 6585) */
117
+ readonly REQUEST_HEADER_FIELDS_TOO_LARGE: 431;
118
+ /** 451 Unavailable For Legal Reasons (RFC 7725) */
119
+ readonly UNAVAILABLE_FOR_LEGAL_REASONS: 451;
120
+ /** 500 Internal Server Error (RFC 9110) */
121
+ readonly INTERNAL_SERVER_ERROR: 500;
122
+ /** 501 Not Implemented (RFC 9110) */
123
+ readonly NOT_IMPLEMENTED: 501;
124
+ /** 502 Bad Gateway (RFC 9110) */
125
+ readonly BAD_GATEWAY: 502;
126
+ /** 503 Service Unavailable (RFC 9110). Consider a `Retry-After` header. */
127
+ readonly SERVICE_UNAVAILABLE: 503;
128
+ /** 504 Gateway Timeout (RFC 9110) */
129
+ readonly GATEWAY_TIMEOUT: 504;
130
+ /** 505 HTTP Version Not Supported (RFC 9110) */
131
+ readonly HTTP_VERSION_NOT_SUPPORTED: 505;
132
+ /** 506 Variant Also Negotiates (RFC 2295) */
133
+ readonly VARIANT_ALSO_NEGOTIATES: 506;
134
+ /** 507 Insufficient Storage (RFC 4918, WebDAV) */
135
+ readonly INSUFFICIENT_STORAGE: 507;
136
+ /** 508 Loop Detected (RFC 5842, WebDAV) */
137
+ readonly LOOP_DETECTED: 508;
138
+ /** 510 Not Extended (RFC 2774). @deprecated Marked obsolete by IANA. */
139
+ readonly NOT_EXTENDED: 510;
140
+ /** 511 Network Authentication Required (RFC 6585) */
141
+ readonly NETWORK_AUTHENTICATION_REQUIRED: 511;
142
+ /** 302. @deprecated HTTP/1.0 name; use `Status.FOUND`. */
143
+ readonly MOVED_TEMPORARILY: 302;
144
+ /** 413. @deprecated RFC 7231 name; use `Status.CONTENT_TOO_LARGE`. */
145
+ readonly PAYLOAD_TOO_LARGE: 413;
146
+ /** 413. @deprecated RFC 2616 name; use `Status.CONTENT_TOO_LARGE`. */
147
+ readonly REQUEST_ENTITY_TOO_LARGE: 413;
148
+ /** 413. @deprecated `http-status-codes` name; use `Status.CONTENT_TOO_LARGE`. */
149
+ readonly REQUEST_TOO_LONG: 413;
150
+ /** 414. @deprecated RFC 2616 name; use `Status.URI_TOO_LONG`. */
151
+ readonly REQUEST_URI_TOO_LONG: 414;
152
+ /** 416. @deprecated RFC 2616 name; use `Status.RANGE_NOT_SATISFIABLE`. */
153
+ readonly REQUESTED_RANGE_NOT_SATISFIABLE: 416;
154
+ /** 422. @deprecated RFC 4918 name; use `Status.UNPROCESSABLE_CONTENT`. */
155
+ readonly UNPROCESSABLE_ENTITY: 422;
156
+ };
157
+ /**
158
+ * Non-standard status codes that are common in the wild. None of them are
159
+ * registered with IANA, and some numbers mean different things to different vendors.
160
+ *
161
+ * ```ts
162
+ * Unofficial.CLIENT_CLOSED_REQUEST // 499 (nginx)
163
+ * Unofficial.IM_A_TEAPOT // 418
164
+ * ```
165
+ */
166
+ declare const Unofficial: {
167
+ /** 104 Upload Resumption Supported (IETF draft, temporary IANA registration) */
168
+ readonly UPLOAD_RESUMPTION_SUPPORTED: 104;
169
+ /** 218 This Is Fine (Apache) */
170
+ readonly THIS_IS_FINE: 218;
171
+ /** 306 Switch Proxy (reserved by RFC 9110, no longer used) */
172
+ readonly SWITCH_PROXY: 306;
173
+ /** 418 I'm a Teapot (RFC 2324 April Fools; reserved by RFC 9110) */
174
+ readonly IM_A_TEAPOT: 418;
175
+ /** 419 Page Expired (Laravel: CSRF token missing or expired) */
176
+ readonly PAGE_EXPIRED: 419;
177
+ /** 420 Enhance Your Calm (Twitter API v1 rate limiting) */
178
+ readonly ENHANCE_YOUR_CALM: 420;
179
+ /** 440 Login Time-out (Microsoft IIS) */
180
+ readonly LOGIN_TIME_OUT: 440;
181
+ /** 444 No Response (nginx: connection closed without a response) */
182
+ readonly NO_RESPONSE: 444;
183
+ /** 449 Retry With (Microsoft IIS) */
184
+ readonly RETRY_WITH: 449;
185
+ /** 450 Blocked by Windows Parental Controls (Microsoft) */
186
+ readonly BLOCKED_BY_WINDOWS_PARENTAL_CONTROLS: 450;
187
+ /** 494 Request Header Too Large (nginx) */
188
+ readonly REQUEST_HEADER_TOO_LARGE: 494;
189
+ /** 495 SSL Certificate Error (nginx) */
190
+ readonly SSL_CERTIFICATE_ERROR: 495;
191
+ /** 496 SSL Certificate Required (nginx) */
192
+ readonly SSL_CERTIFICATE_REQUIRED: 496;
193
+ /** 497 HTTP Request Sent to HTTPS Port (nginx) */
194
+ readonly HTTP_REQUEST_SENT_TO_HTTPS_PORT: 497;
195
+ /** 498 Invalid Token (Esri ArcGIS) */
196
+ readonly INVALID_TOKEN: 498;
197
+ /** 499 Client Closed Request (nginx) */
198
+ readonly CLIENT_CLOSED_REQUEST: 499;
199
+ /** 509 Bandwidth Limit Exceeded (Apache, cPanel) */
200
+ readonly BANDWIDTH_LIMIT_EXCEEDED: 509;
201
+ /** 520 Unknown Error (Cloudflare: origin returned something unexpected) */
202
+ readonly UNKNOWN_ERROR: 520;
203
+ /** 521 Web Server Is Down (Cloudflare: origin refused the connection) */
204
+ readonly WEB_SERVER_IS_DOWN: 521;
205
+ /** 522 Connection Timed Out (Cloudflare: TCP connection to origin timed out) */
206
+ readonly CONNECTION_TIMED_OUT: 522;
207
+ /** 523 Origin Is Unreachable (Cloudflare) */
208
+ readonly ORIGIN_IS_UNREACHABLE: 523;
209
+ /** 524 A Timeout Occurred (Cloudflare: origin did not send a response in time) */
210
+ readonly A_TIMEOUT_OCCURRED: 524;
211
+ /** 525 SSL Handshake Failed (Cloudflare) */
212
+ readonly SSL_HANDSHAKE_FAILED: 525;
213
+ /** 526 Invalid SSL Certificate (Cloudflare) */
214
+ readonly INVALID_SSL_CERTIFICATE: 526;
215
+ /** 527 Railgun Error (Cloudflare). @deprecated Railgun has been retired. */
216
+ readonly RAILGUN_ERROR: 527;
217
+ /** 598 Network Read Timeout Error (some proxies) */
218
+ readonly NETWORK_READ_TIMEOUT_ERROR: 598;
219
+ /** 599 Network Connect Timeout Error (some proxies) */
220
+ readonly NETWORK_CONNECT_TIMEOUT_ERROR: 599;
221
+ };
222
+ /**
223
+ * Reason phrase for every known code, official (RFC 9110 wording) and unofficial.
224
+ *
225
+ * ```ts
226
+ * Reason[404] // 'Not Found' (type: 'Not Found')
227
+ * Reason[413] // 'Content Too Large'
228
+ * ```
229
+ */
230
+ declare const Reason: {
231
+ readonly 100: "Continue";
232
+ readonly 101: "Switching Protocols";
233
+ readonly 102: "Processing";
234
+ readonly 103: "Early Hints";
235
+ readonly 104: "Upload Resumption Supported";
236
+ readonly 200: "OK";
237
+ readonly 201: "Created";
238
+ readonly 202: "Accepted";
239
+ readonly 203: "Non-Authoritative Information";
240
+ readonly 204: "No Content";
241
+ readonly 205: "Reset Content";
242
+ readonly 206: "Partial Content";
243
+ readonly 207: "Multi-Status";
244
+ readonly 208: "Already Reported";
245
+ readonly 218: "This Is Fine";
246
+ readonly 226: "IM Used";
247
+ readonly 300: "Multiple Choices";
248
+ readonly 301: "Moved Permanently";
249
+ readonly 302: "Found";
250
+ readonly 303: "See Other";
251
+ readonly 304: "Not Modified";
252
+ readonly 305: "Use Proxy";
253
+ readonly 306: "Switch Proxy";
254
+ readonly 307: "Temporary Redirect";
255
+ readonly 308: "Permanent Redirect";
256
+ readonly 400: "Bad Request";
257
+ readonly 401: "Unauthorized";
258
+ readonly 402: "Payment Required";
259
+ readonly 403: "Forbidden";
260
+ readonly 404: "Not Found";
261
+ readonly 405: "Method Not Allowed";
262
+ readonly 406: "Not Acceptable";
263
+ readonly 407: "Proxy Authentication Required";
264
+ readonly 408: "Request Timeout";
265
+ readonly 409: "Conflict";
266
+ readonly 410: "Gone";
267
+ readonly 411: "Length Required";
268
+ readonly 412: "Precondition Failed";
269
+ readonly 413: "Content Too Large";
270
+ readonly 414: "URI Too Long";
271
+ readonly 415: "Unsupported Media Type";
272
+ readonly 416: "Range Not Satisfiable";
273
+ readonly 417: "Expectation Failed";
274
+ readonly 418: "I'm a Teapot";
275
+ readonly 419: "Page Expired";
276
+ readonly 420: "Enhance Your Calm";
277
+ readonly 421: "Misdirected Request";
278
+ readonly 422: "Unprocessable Content";
279
+ readonly 423: "Locked";
280
+ readonly 424: "Failed Dependency";
281
+ readonly 425: "Too Early";
282
+ readonly 426: "Upgrade Required";
283
+ readonly 428: "Precondition Required";
284
+ readonly 429: "Too Many Requests";
285
+ readonly 431: "Request Header Fields Too Large";
286
+ readonly 440: "Login Time-out";
287
+ readonly 444: "No Response";
288
+ readonly 449: "Retry With";
289
+ readonly 450: "Blocked by Windows Parental Controls";
290
+ readonly 451: "Unavailable For Legal Reasons";
291
+ readonly 494: "Request Header Too Large";
292
+ readonly 495: "SSL Certificate Error";
293
+ readonly 496: "SSL Certificate Required";
294
+ readonly 497: "HTTP Request Sent to HTTPS Port";
295
+ readonly 498: "Invalid Token";
296
+ readonly 499: "Client Closed Request";
297
+ readonly 500: "Internal Server Error";
298
+ readonly 501: "Not Implemented";
299
+ readonly 502: "Bad Gateway";
300
+ readonly 503: "Service Unavailable";
301
+ readonly 504: "Gateway Timeout";
302
+ readonly 505: "HTTP Version Not Supported";
303
+ readonly 506: "Variant Also Negotiates";
304
+ readonly 507: "Insufficient Storage";
305
+ readonly 508: "Loop Detected";
306
+ readonly 509: "Bandwidth Limit Exceeded";
307
+ readonly 510: "Not Extended";
308
+ readonly 511: "Network Authentication Required";
309
+ readonly 520: "Unknown Error";
310
+ readonly 521: "Web Server Is Down";
311
+ readonly 522: "Connection Timed Out";
312
+ readonly 523: "Origin Is Unreachable";
313
+ readonly 524: "A Timeout Occurred";
314
+ readonly 525: "SSL Handshake Failed";
315
+ readonly 526: "Invalid SSL Certificate";
316
+ readonly 527: "Railgun Error";
317
+ readonly 598: "Network Read Timeout Error";
318
+ readonly 599: "Network Connect Timeout Error";
319
+ };
320
+ /** Names of the constants in {@link Status}, e.g. `'NOT_FOUND'`. */
321
+ type StatusName = keyof typeof Status;
322
+ /** Names of the constants in {@link Unofficial}, e.g. `'CLIENT_CLOSED_REQUEST'`. */
323
+ type UnofficialStatusName = keyof typeof Unofficial;
324
+ /** Every IANA-registered status code: `100 | 101 | ... | 511`. */
325
+ type StatusCode = (typeof Status)[StatusName];
326
+ /** Every non-standard code in {@link Unofficial}: `104 | 218 | 306 | 418 | ... | 599`. */
327
+ type UnofficialStatusCode = (typeof Unofficial)[UnofficialStatusName];
328
+ /** Every code this package knows: official and unofficial. */
329
+ type KnownStatusCode = StatusCode | UnofficialStatusCode;
330
+ type StartsWith<C, D extends string> = C extends number ? (`${C}` extends `${D}${string}` ? C : never) : never;
331
+ /** Official 1xx codes. */
332
+ type InformationalStatus = StartsWith<StatusCode, '1'>;
333
+ /** Official 2xx codes. */
334
+ type SuccessStatus = StartsWith<StatusCode, '2'>;
335
+ /** Official 3xx codes. */
336
+ type RedirectionStatus = StartsWith<StatusCode, '3'>;
337
+ /** Official 4xx codes. */
338
+ type ClientErrorStatus = StartsWith<StatusCode, '4'>;
339
+ /** Official 5xx codes. */
340
+ type ServerErrorStatus = StartsWith<StatusCode, '5'>;
341
+ /** Official 4xx and 5xx codes. */
342
+ type ErrorStatus = ClientErrorStatus | ServerErrorStatus;
343
+ /** The reason phrase of a known code: `ReasonPhrase<404>` is `'Not Found'`. Without a parameter, every known phrase. */
344
+ type ReasonPhrase<C extends KnownStatusCode = KnownStatusCode> = (typeof Reason)[C];
345
+ /** The code for a reason phrase: `CodeOf<'Not Found'>` is `404`. */
346
+ type CodeOf<P extends ReasonPhrase> = {
347
+ [C in KnownStatusCode]: (typeof Reason)[C] extends P ? C : never;
348
+ }[KnownStatusCode];
349
+
350
+ /** The class of a status code, from its first digit. */
351
+ type Category = 'informational' | 'success' | 'redirection' | 'client-error' | 'server-error';
352
+ /**
353
+ * `true` for any integer from 100 to 599, the range RFC 9110 allows,
354
+ * whether or not the code is registered. Type guard: strings are always `false`.
355
+ */
356
+ declare const isValid: (code: unknown) => code is number;
357
+ /** `true` if this package knows the code (official or unofficial). Type guard: strings are always `false`. */
358
+ declare const isKnown: (code: unknown) => code is KnownStatusCode;
359
+ /** `true` if the code is registered with IANA (`Status`), not just common in the wild. Type guard: strings are always `false`. */
360
+ declare const isOfficial: (code: unknown) => code is StatusCode;
361
+ /** 1xx */
362
+ declare const isInformational: (code: unknown) => boolean;
363
+ /** 2xx */
364
+ declare const isSuccess: (code: unknown) => boolean;
365
+ /** 3xx, including 304 Not Modified. See {@link isRedirect} for codes that send you somewhere else. */
366
+ declare const isRedirection: (code: unknown) => boolean;
367
+ /** 4xx */
368
+ declare const isClientError: (code: unknown) => boolean;
369
+ /** 5xx */
370
+ declare const isServerError: (code: unknown) => boolean;
371
+ /** 4xx or 5xx */
372
+ declare const isError: (code: unknown) => boolean;
373
+ /**
374
+ * `true` for redirects a client follows via the `Location` header:
375
+ * 301, 302, 303, 307, 308 (the Fetch standard's "redirect status").
376
+ * 300 and 304 are 3xx but not followed automatically.
377
+ */
378
+ declare const isRedirect: (code: unknown) => boolean;
379
+ /**
380
+ * `true` for redirects that must repeat the request with the same method and body:
381
+ * 307 and 308. Clients may turn a POST into a GET for 301 and 302, and must for 303.
382
+ */
383
+ declare const isRedirectWithBody: (code: unknown) => boolean;
384
+ /**
385
+ * `true` for codes where retrying the same request later can succeed:
386
+ * 408, 425, 429, 500, 502, 503, 504. Check the `Retry-After` header for 429 and 503.
387
+ */
388
+ declare const isRetryable: (code: unknown) => boolean;
389
+ /** `true` for responses that never have a body: 1xx, 204, 205, 304. */
390
+ declare const isEmptyBody: (code: unknown) => boolean;
391
+ /**
392
+ * `true` for codes that caches may store without explicit freshness headers
393
+ * ("heuristically cacheable", RFC 9110 section 15.1):
394
+ * 200, 203, 204, 206, 300, 301, 308, 404, 405, 410, 414, 501.
395
+ */
396
+ declare const isCacheable: (code: unknown) => boolean;
397
+ /** The category of a code, or `undefined` if it is not an integer from 100 to 599. */
398
+ declare const category: (code: unknown) => Category | undefined;
399
+ interface ReasonOptions {
400
+ /**
401
+ * Return the pre-RFC 9110 phrase that Node.js `http.STATUS_CODES` and `statuses` use:
402
+ * 413 `'Payload Too Large'` and 422 `'Unprocessable Entity'`. Other codes are unchanged.
403
+ */
404
+ legacy?: boolean;
405
+ }
406
+ /**
407
+ * The reason phrase for a status code, or `undefined` if the code is unknown.
408
+ *
409
+ * ```ts
410
+ * reason(404) // 'Not Found'
411
+ * reason(413) // 'Content Too Large'
412
+ * reason(413, { legacy: true }) // 'Payload Too Large'
413
+ * reason('503') // 'Service Unavailable'
414
+ * reason(299) // undefined
415
+ * ```
416
+ */
417
+ declare function reason<C extends KnownStatusCode>(code: C, options?: {
418
+ legacy?: false;
419
+ }): ReasonPhrase<C>;
420
+ declare function reason(code: number | string, options?: ReasonOptions): string | undefined;
421
+ /**
422
+ * The status code for a reason phrase or constant name, or `undefined` if unknown.
423
+ * Case, spaces, hyphens, underscores and apostrophes are ignored, and legacy names work too.
424
+ *
425
+ * ```ts
426
+ * code('Not Found') // 404
427
+ * code('not found') // 404
428
+ * code('NOT_FOUND') // 404
429
+ * code('Payload Too Large') // 413 (legacy name)
430
+ * code("i'm a teapot") // 418
431
+ * code('404') // 404
432
+ * code('Nope') // undefined
433
+ * ```
434
+ */
435
+ declare function code<P extends ReasonPhrase>(phrase: P): CodeOf<P>;
436
+ declare function code(phrase: string): KnownStatusCode | undefined;
437
+ interface AllCodesOptions {
438
+ /** Include the non-standard codes from `Unofficial`. Default `false`. */
439
+ unofficial?: boolean;
440
+ }
441
+ /**
442
+ * Every known code, sorted ascending. Official (IANA) codes only, unless `unofficial: true`.
443
+ *
444
+ * ```ts
445
+ * allCodes() // [100, 101, 102, 103, 200, ...]
446
+ * allCodes({ unofficial: true }) // [100, 101, 102, 103, 104, 200, ...]
447
+ * ```
448
+ */
449
+ declare function allCodes(options?: {
450
+ unofficial?: false;
451
+ }): StatusCode[];
452
+ declare function allCodes(options: AllCodesOptions): KnownStatusCode[];
453
+
454
+ /** Everything known about a status code, returned by {@link info}. */
455
+ interface StatusInfo<C extends KnownStatusCode = KnownStatusCode> {
456
+ /** The numeric code, e.g. `404`. */
457
+ code: C;
458
+ /** The reason phrase (RFC 9110 wording for official codes), e.g. `'Not Found'`. */
459
+ reason: ReasonPhrase<C>;
460
+ /** The constant name in `Status` or `Unofficial`, e.g. `'NOT_FOUND'`. */
461
+ name: string;
462
+ /** `'informational'`, `'success'`, `'redirection'`, `'client-error'` or `'server-error'`. */
463
+ category: Category;
464
+ /** `true` if registered with IANA; `false` for vendor-specific and reserved codes. */
465
+ official: boolean;
466
+ /** `true` if the code is deprecated, obsolete or retired (305, 510, 527). */
467
+ deprecated: boolean;
468
+ /** Where the code is defined: `'RFC 9110, Section 15.5.5'`, `'nginx'`, `'Cloudflare'`, ... */
469
+ spec: string;
470
+ /** Link to the definition, when there is a public spec. */
471
+ url: string | undefined;
472
+ /** One-sentence description of what the code means. */
473
+ description: string;
474
+ /** Older reason phrases for the same code, e.g. `['Payload Too Large', 'Request Entity Too Large']` for 413. */
475
+ aliases: readonly string[];
476
+ /** See {@link isRetryable}. */
477
+ retryable: boolean;
478
+ /** Heuristically cacheable by default (RFC 9110 section 15.1). See {@link isCacheable}. */
479
+ cacheable: boolean;
480
+ /** The response never has a body. See {@link isEmptyBody}. */
481
+ emptyBody: boolean;
482
+ }
483
+ /**
484
+ * Everything known about a status code, or `undefined` if the code is unknown.
485
+ *
486
+ * ```ts
487
+ * info(429)
488
+ * // {
489
+ * // code: 429, reason: 'Too Many Requests', name: 'TOO_MANY_REQUESTS',
490
+ * // category: 'client-error', official: true, deprecated: false,
491
+ * // spec: 'RFC 6585, Section 4', url: 'https://www.rfc-editor.org/rfc/rfc6585#section-4',
492
+ * // description: 'The client sent too many requests in a given time (rate limiting).',
493
+ * // aliases: [], retryable: true, cacheable: false, emptyBody: false,
494
+ * // }
495
+ * ```
496
+ */
497
+ declare function info<C extends KnownStatusCode>(code: C): StatusInfo<C>;
498
+ declare function info(code: number | string): StatusInfo | undefined;
499
+
500
+ /** The `application/problem+json` media type from RFC 9457. */
501
+ declare const PROBLEM_JSON = "application/problem+json";
502
+ /** An RFC 9457 problem details object, as returned by {@link HttpError.toJSON}. */
503
+ interface ProblemDetails {
504
+ /** A URI identifying the problem type. `'about:blank'` means "nothing beyond the status code". */
505
+ type: string;
506
+ /** A short summary of the problem type. With `about:blank` this is the reason phrase. */
507
+ title: string;
508
+ /** The HTTP status code. */
509
+ status: number;
510
+ /** An explanation of this occurrence. Only present when the error is exposed. */
511
+ detail?: string;
512
+ /** A URI identifying this occurrence. */
513
+ instance?: string;
514
+ /** Extension members. */
515
+ [extension: string]: unknown;
516
+ }
517
+ interface HttpErrorOptions {
518
+ /** The underlying error, kept as `error.cause`. */
519
+ cause?: unknown;
520
+ /** Response headers to send with the error, e.g. `{ 'Retry-After': '120' }` for 429. */
521
+ headers?: Record<string, string>;
522
+ /**
523
+ * Whether the message is safe to show to clients. Default: `true` for 4xx, `false` for 5xx.
524
+ * When `false`, `toJSON()` leaves out `detail` so internal messages do not leak.
525
+ */
526
+ expose?: boolean;
527
+ /** RFC 9457 problem type URI. Default `'about:blank'`. */
528
+ type?: string;
529
+ /** RFC 9457 title. Default: the reason phrase. */
530
+ title?: string;
531
+ /** RFC 9457 instance URI identifying this occurrence. */
532
+ instance?: string;
533
+ /** Extra members for `toJSON()`, e.g. `{ errors: [...] }`. They cannot override `type`, `title`, `status`, `detail` or `instance`. */
534
+ extensions?: Record<string, unknown>;
535
+ }
536
+ /**
537
+ * An error carrying an HTTP status code. Same shape as an `http-errors` error
538
+ * (`status`, `statusCode`, `expose`, `headers`), and serializes to RFC 9457 problem details.
539
+ *
540
+ * ```ts
541
+ * throw new HttpError(404) // message 'Not Found'
542
+ * throw new HttpError(404, 'No user with id 42')
543
+ * throw new HttpError(429, { headers: { 'Retry-After': '60' } })
544
+ * throw new HttpError(502, 'Upstream failed', { cause: err })
545
+ * ```
546
+ */
547
+ declare class HttpError<S extends number = number> extends Error {
548
+ /** The HTTP status code, 400-599. */
549
+ readonly status: S;
550
+ /** Same as `status`, for code that reads `statusCode`. */
551
+ readonly statusCode: S;
552
+ /** Whether `message` is safe to send to the client. */
553
+ readonly expose: boolean;
554
+ /** Headers to set on the response. */
555
+ readonly headers: Readonly<Record<string, string>>;
556
+ /** RFC 9457 problem type URI. */
557
+ readonly type: string;
558
+ /** RFC 9457 title. */
559
+ readonly title: string;
560
+ /** RFC 9457 instance URI. */
561
+ readonly instance: string | undefined;
562
+ /** Extra RFC 9457 members. */
563
+ readonly extensions: Readonly<Record<string, unknown>>;
564
+ constructor(status: S, message?: string, options?: HttpErrorOptions);
565
+ constructor(status: S, options?: HttpErrorOptions);
566
+ /**
567
+ * RFC 9457 problem details. `detail` is the message, included only when the error
568
+ * is exposed and the message says more than the title.
569
+ *
570
+ * ```ts
571
+ * new HttpError(404, 'No user with id 42').toJSON()
572
+ * // { type: 'about:blank', title: 'Not Found', status: 404, detail: 'No user with id 42' }
573
+ * ```
574
+ */
575
+ toJSON(): ProblemDetails;
576
+ /**
577
+ * A web-standard `Response` with the problem details as `application/problem+json`
578
+ * and the error's headers. Handy in fetch handlers, edge functions, Bun and Deno.
579
+ */
580
+ toResponse(): Response;
581
+ }
582
+ /**
583
+ * `true` for an {@link HttpError}, including one created by another copy of this package
584
+ * (duplicate installs, other realms).
585
+ */
586
+ declare const isHttpError: (value: unknown) => value is HttpError;
587
+ /**
588
+ * Creates an {@link HttpError}. Same arguments as `new HttpError(...)`.
589
+ *
590
+ * ```ts
591
+ * throw createError(404)
592
+ * throw createError(403, 'Admins only')
593
+ * throw createError(503, { headers: { 'Retry-After': '30' } })
594
+ * ```
595
+ */
596
+ declare function createError<S extends number>(status: S, message?: string, options?: HttpErrorOptions): HttpError<S>;
597
+ declare function createError<S extends number>(status: S, options?: HttpErrorOptions): HttpError<S>;
598
+
599
+ export { type AllCodesOptions, type Category, type ClientErrorStatus, type CodeOf, type ErrorStatus, HttpError, type HttpErrorOptions, type InformationalStatus, type KnownStatusCode, PROBLEM_JSON, type ProblemDetails, Reason, type ReasonOptions, type ReasonPhrase, type RedirectionStatus, type ServerErrorStatus, Status, type StatusCode, type StatusInfo, type StatusName, type SuccessStatus, Unofficial, type UnofficialStatusCode, type UnofficialStatusName, allCodes, category, code, createError, info, isCacheable, isClientError, isEmptyBody, isError, isHttpError, isInformational, isKnown, isOfficial, isRedirect, isRedirectWithBody, isRedirection, isRetryable, isServerError, isSuccess, isValid, reason };
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ var c={CONTINUE:100,SWITCHING_PROTOCOLS:101,PROCESSING:102,EARLY_HINTS:103,OK:200,CREATED:201,ACCEPTED:202,NON_AUTHORITATIVE_INFORMATION:203,NO_CONTENT:204,RESET_CONTENT:205,PARTIAL_CONTENT:206,MULTI_STATUS:207,ALREADY_REPORTED:208,IM_USED:226,MULTIPLE_CHOICES:300,MOVED_PERMANENTLY:301,FOUND:302,SEE_OTHER:303,NOT_MODIFIED:304,USE_PROXY:305,TEMPORARY_REDIRECT:307,PERMANENT_REDIRECT:308,BAD_REQUEST:400,UNAUTHORIZED:401,PAYMENT_REQUIRED:402,FORBIDDEN:403,NOT_FOUND:404,METHOD_NOT_ALLOWED:405,NOT_ACCEPTABLE:406,PROXY_AUTHENTICATION_REQUIRED:407,REQUEST_TIMEOUT:408,CONFLICT:409,GONE:410,LENGTH_REQUIRED:411,PRECONDITION_FAILED:412,CONTENT_TOO_LARGE:413,URI_TOO_LONG:414,UNSUPPORTED_MEDIA_TYPE:415,RANGE_NOT_SATISFIABLE:416,EXPECTATION_FAILED:417,MISDIRECTED_REQUEST:421,UNPROCESSABLE_CONTENT:422,LOCKED:423,FAILED_DEPENDENCY:424,TOO_EARLY:425,UPGRADE_REQUIRED:426,PRECONDITION_REQUIRED:428,TOO_MANY_REQUESTS:429,REQUEST_HEADER_FIELDS_TOO_LARGE:431,UNAVAILABLE_FOR_LEGAL_REASONS:451,INTERNAL_SERVER_ERROR:500,NOT_IMPLEMENTED:501,BAD_GATEWAY:502,SERVICE_UNAVAILABLE:503,GATEWAY_TIMEOUT:504,HTTP_VERSION_NOT_SUPPORTED:505,VARIANT_ALSO_NEGOTIATES:506,INSUFFICIENT_STORAGE:507,LOOP_DETECTED:508,NOT_EXTENDED:510,NETWORK_AUTHENTICATION_REQUIRED:511,MOVED_TEMPORARILY:302,PAYLOAD_TOO_LARGE:413,REQUEST_ENTITY_TOO_LARGE:413,REQUEST_TOO_LONG:413,REQUEST_URI_TOO_LONG:414,REQUESTED_RANGE_NOT_SATISFIABLE:416,UNPROCESSABLE_ENTITY:422},u={UPLOAD_RESUMPTION_SUPPORTED:104,THIS_IS_FINE:218,SWITCH_PROXY:306,IM_A_TEAPOT:418,PAGE_EXPIRED:419,ENHANCE_YOUR_CALM:420,LOGIN_TIME_OUT:440,NO_RESPONSE:444,RETRY_WITH:449,BLOCKED_BY_WINDOWS_PARENTAL_CONTROLS:450,REQUEST_HEADER_TOO_LARGE:494,SSL_CERTIFICATE_ERROR:495,SSL_CERTIFICATE_REQUIRED:496,HTTP_REQUEST_SENT_TO_HTTPS_PORT:497,INVALID_TOKEN:498,CLIENT_CLOSED_REQUEST:499,BANDWIDTH_LIMIT_EXCEEDED:509,UNKNOWN_ERROR:520,WEB_SERVER_IS_DOWN:521,CONNECTION_TIMED_OUT:522,ORIGIN_IS_UNREACHABLE:523,A_TIMEOUT_OCCURRED:524,SSL_HANDSHAKE_FAILED:525,INVALID_SSL_CERTIFICATE:526,RAILGUN_ERROR:527,NETWORK_READ_TIMEOUT_ERROR:598,NETWORK_CONNECT_TIMEOUT_ERROR:599},a={100:"Continue",101:"Switching Protocols",102:"Processing",103:"Early Hints",104:"Upload Resumption Supported",200:"OK",201:"Created",202:"Accepted",203:"Non-Authoritative Information",204:"No Content",205:"Reset Content",206:"Partial Content",207:"Multi-Status",208:"Already Reported",218:"This Is Fine",226:"IM Used",300:"Multiple Choices",301:"Moved Permanently",302:"Found",303:"See Other",304:"Not Modified",305:"Use Proxy",306:"Switch Proxy",307:"Temporary Redirect",308:"Permanent Redirect",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",409:"Conflict",410:"Gone",411:"Length Required",412:"Precondition Failed",413:"Content Too Large",414:"URI Too Long",415:"Unsupported Media Type",416:"Range Not Satisfiable",417:"Expectation Failed",418:"I'm a Teapot",419:"Page Expired",420:"Enhance Your Calm",421:"Misdirected Request",422:"Unprocessable Content",423:"Locked",424:"Failed Dependency",425:"Too Early",426:"Upgrade Required",428:"Precondition Required",429:"Too Many Requests",431:"Request Header Fields Too Large",440:"Login Time-out",444:"No Response",449:"Retry With",450:"Blocked by Windows Parental Controls",451:"Unavailable For Legal Reasons",494:"Request Header Too Large",495:"SSL Certificate Error",496:"SSL Certificate Required",497:"HTTP Request Sent to HTTPS Port",498:"Invalid Token",499:"Client Closed Request",500:"Internal Server Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Gateway Timeout",505:"HTTP Version Not Supported",506:"Variant Also Negotiates",507:"Insufficient Storage",508:"Loop Detected",509:"Bandwidth Limit Exceeded",510:"Not Extended",511:"Network Authentication Required",520:"Unknown Error",521:"Web Server Is Down",522:"Connection Timed Out",523:"Origin Is Unreachable",524:"A Timeout Occurred",525:"SSL Handshake Failed",526:"Invalid SSL Certificate",527:"Railgun Error",598:"Network Read Timeout Error",599:"Network Connect Timeout Error"},h={302:["Moved Temporarily"],413:["Payload Too Large","Request Entity Too Large"],414:["Request-URI Too Long","Request-URI Too Large"],416:["Requested Range Not Satisfiable"],422:["Unprocessable Entity"]},b={413:"Payload Too Large",422:"Unprocessable Entity"};var N=e=>Object.values(u).includes(e),L=["informational","success","redirection","client-error","server-error"],s=e=>typeof e=="number"?e:typeof e=="string"&&/^\s*\d{3}\s*$/.test(e)?Number(e):NaN,i=(e,t,o)=>{let r=s(e);return Number.isInteger(r)&&r>=t&&r<=o},l=e=>i(e,100,599)&&Object.prototype.hasOwnProperty.call(a,s(e)),U=e=>typeof e=="number"&&i(e,100,599),_=e=>typeof e=="number"&&l(e),T=e=>_(e)&&!N(e),A=e=>i(e,100,199),P=e=>i(e,200,299),D=e=>i(e,300,399),R=e=>i(e,400,499),v=e=>i(e,500,599),S=e=>i(e,400,599),k=e=>[301,302,303,307,308].includes(s(e)),q=e=>[307,308].includes(s(e)),m=e=>[408,425,429,500,502,503,504].includes(s(e)),C=e=>A(e)||[204,205,304].includes(s(e)),O=e=>[200,203,204,206,300,301,308,404,405,410,414,501].includes(s(e)),g=e=>i(e,100,599)?L[Math.floor(s(e)/100)-1]:void 0;function y(e,t){if(!l(e))return;let o=s(e);return t?.legacy&&b[o]||a[o]}var E=e=>e.toLowerCase().replace(/[^a-z0-9]/g,""),d,H=()=>{if(d)return d;d=new Map;for(let e of[c,u])for(let[t,o]of Object.entries(e))d.set(E(t),o);for(let[e,t]of Object.entries(h))for(let o of t)d.set(E(o),Number(e));for(let[e,t]of Object.entries(a))d.set(E(t),Number(e));return d};function M(e){if(typeof e!="string")return;if(l(e))return s(e);let t=E(e);return t?H().get(t):void 0}function F(e){return Object.keys(a).map(Number).filter(t=>e?.unofficial||!N(t)).sort((t,o)=>t-o)}var W={100:["9110:15.2.1","The request headers were received and the client should send the request body."],101:["9110:15.2.2","The server is switching to the protocol named in the Upgrade header, such as WebSocket."],102:["2518:10.1","The server accepted the request and is still working on it (WebDAV)."],103:["8297:2","Preliminary headers, usually Link preload hints, sent before the final response."],104:["draft-ietf-httpbis-resumable-upload","The server supports resumable uploads; the client can resume an interrupted upload."],200:["9110:15.3.1","The request succeeded."],201:["9110:15.3.2","The request succeeded and created a new resource, usually identified by the Location header."],202:["9110:15.3.3","The request was accepted for processing, but processing has not finished."],203:["9110:15.3.4","The request succeeded, but a transforming proxy modified the content."],204:["9110:15.3.5","The request succeeded and there is no content to send."],205:["9110:15.3.6","The request succeeded and the client should reset the document view, such as clearing a form."],206:["9110:15.3.7","The response contains only the byte ranges the client asked for in the Range header."],207:["4918:11.1","The body contains separate status codes for several resources (WebDAV)."],208:["5842:7.1","Members of a WebDAV binding were already listed earlier in this response."],218:["Apache","Catch-all error that lets the original response through, used by Apache servers on Pantheon."],226:["3229:10.4.1","The server applied instance manipulations (such as a delta encoding) to the current resource."],300:["9110:15.4.1","The resource has several representations and the client should pick one."],301:["9110:15.4.2","The resource moved permanently to the URL in the Location header."],302:["9110:15.4.3","The resource is temporarily at the URL in the Location header."],303:["9110:15.4.4","See the URL in the Location header, fetched with GET, for the result."],304:["9110:15.4.5","The cached copy is still valid; no body is sent."],305:["9110:15.4.6","The resource must be accessed through a proxy. Deprecated for security reasons."],306:["9110:15.4.7","Reserved. Used in an old draft of HTTP/1.1 and no longer used."],307:["9110:15.4.8","The resource is temporarily at the URL in the Location header; repeat the request with the same method and body."],308:["9110:15.4.9","The resource moved permanently to the URL in the Location header; repeat the request with the same method and body."],400:["9110:15.5.1","The server cannot process the request because it is malformed or invalid."],401:["9110:15.5.2","The request lacks valid authentication credentials for the resource."],402:["9110:15.5.3","Reserved for future use; some APIs use it when payment is required."],403:["9110:15.5.4","The server understood the request but refuses to fulfill it."],404:["9110:15.5.5","The server has no resource at this URL."],405:["9110:15.5.6","The resource does not support this request method."],406:["9110:15.5.7","No representation matches the Accept headers of the request."],407:["9110:15.5.8","The client must authenticate with the proxy first."],408:["9110:15.5.9","The server timed out waiting for the complete request."],409:["9110:15.5.10","The request conflicts with the current state of the resource."],410:["9110:15.5.11","The resource is permanently gone and will not come back."],411:["9110:15.5.12","The request needs a Content-Length header."],412:["9110:15.5.13","A condition in the request headers, such as If-Match, was false."],413:["9110:15.5.14","The request content is larger than the server is willing to process."],414:["9110:15.5.15","The request URL is longer than the server is willing to process."],415:["9110:15.5.16","The request content is in a format the resource does not support."],416:["9110:15.5.17","The ranges in the Range header cannot be satisfied."],417:["9110:15.5.18","The server cannot meet the Expect request header."],418:["2324:2.3.2","A teapot refuses to brew coffee. An April Fools joke, reserved by RFC 9110 so it is never assigned."],419:["Laravel","The CSRF token is missing or expired."],420:["Twitter","The client is being rate limited (Twitter API v1). Use 429 instead."],421:["9110:15.5.20","The request was sent to a server that cannot produce a response for this URL."],422:["9110:15.5.21","The request is well-formed but its content fails validation."],423:["4918:11.3","The resource is locked (WebDAV)."],424:["4918:11.4","The request failed because a request it depends on failed (WebDAV)."],425:["8470:5.2","The server will not process a request that might be replayed (TLS early data)."],426:["9110:15.5.22","The client must switch to the protocol named in the Upgrade header."],428:["6585:3","The request must be conditional, for example with If-Match, to avoid lost updates."],429:["6585:4","The client sent too many requests in a given time (rate limiting)."],431:["6585:5","A header field, or all headers together, are too large."],440:["Microsoft IIS","The client's session has expired and the user must log in again."],444:["nginx","nginx closed the connection without sending a response."],449:["Microsoft IIS","The request should be retried after performing the appropriate action."],450:["Microsoft","Windows Parental Controls blocked access to the page."],451:["7725:3","The resource is unavailable for legal reasons, such as censorship or a court order."],494:["nginx","The request headers are too large (nginx)."],495:["nginx","The client certificate failed verification (nginx)."],496:["nginx","A client certificate is required but was not sent (nginx)."],497:["nginx","A plain HTTP request was sent to an HTTPS port (nginx)."],498:["Esri ArcGIS","The token is expired or invalid (Esri ArcGIS)."],499:["nginx","The client closed the connection before the server responded (nginx)."],500:["9110:15.6.1","The server hit an unexpected condition."],501:["9110:15.6.2","The server does not support the functionality needed for the request."],502:["9110:15.6.3","A gateway or proxy got an invalid response from the upstream server."],503:["9110:15.6.4","The server is temporarily unable to handle the request, for example overloaded or in maintenance."],504:["9110:15.6.5","A gateway or proxy did not get a response from the upstream server in time."],505:["9110:15.6.6","The server does not support the HTTP version of the request."],506:["2295:8.1","Transparent content negotiation is misconfigured and loops."],507:["4918:11.5","The server cannot store what is needed to complete the request (WebDAV)."],508:["5842:7.2","The server found an infinite loop while processing the request (WebDAV)."],509:["Apache","The site exceeded the bandwidth limit set by the hosting provider."],510:["2774:7","The request needs further extensions. Obsolete: the HTTP Extension Framework is historic."],511:["6585:6","The client must authenticate to gain network access, e.g. a captive portal."],520:["Cloudflare","The origin server returned an empty, unknown or unexpected response to Cloudflare."],521:["Cloudflare","The origin server refused the connection from Cloudflare."],522:["Cloudflare","Cloudflare timed out connecting to the origin server."],523:["Cloudflare","Cloudflare could not reach the origin server, for example because of a DNS problem."],524:["Cloudflare","Cloudflare connected to the origin server, but it did not respond in time."],525:["Cloudflare","The TLS handshake between Cloudflare and the origin server failed."],526:["Cloudflare","Cloudflare could not validate the TLS certificate of the origin server."],527:["Cloudflare","The connection between Cloudflare and the Railgun listener failed. Railgun is retired."],598:["Proxy convention","A proxy timed out reading the response from the upstream server."],599:["Proxy convention","A proxy timed out connecting to the upstream server."]},G=[305,510,527],K=e=>{let t=/^(\d+):(.+)$/.exec(e);return t?[`RFC ${t[1]}, Section ${t[2]}`,`https://www.rfc-editor.org/rfc/rfc${t[1]}#section-${t[2]}`]:e.startsWith("draft-")?[`IETF ${e}`,`https://datatracker.ietf.org/doc/${e}/`]:[e,void 0]},B=e=>{for(let t of[c,u])for(let[o,r]of Object.entries(t))if(r===e)return o;return""};function Y(e){if(!l(e))return;let t=Number(e),[o,r]=W[t],[n,f]=K(o);return{code:t,reason:a[t],name:B(t),category:g(t),official:T(t),deprecated:G.includes(t),spec:n,url:f,description:r,aliases:h[t]??[],retryable:m(t),cacheable:O(t),emptyBody:C(t)}}var x="application/problem+json",w="fourohfour.HttpError",V=["type","title","status","detail","instance"],I=e=>y(e)??(R(e)?"Client Error":"Server Error"),p=class extends Error{constructor(t,o,r){if(!S(t)||typeof t!="number")throw new RangeError(`HttpError status must be an integer from 400 to 599, got ${typeof t=="number"?t:typeof t}`);let n=(typeof o=="object"&&o!==null?o:r)??{},f=typeof o=="string"?o:I(t);super(f,"cause"in n?{cause:n.cause}:void 0),"cause"in n&&!("cause"in this)&&(this.cause=n.cause),this.name="HttpError",this.status=t,this.statusCode=t,this.expose=n.expose??t<500,this.headers={...n.headers},this.type=n.type??"about:blank",this.title=n.title??I(t),this.instance=n.instance,this.extensions={...n.extensions},Object.defineProperty(this,Symbol.for(w),{value:!0})}toJSON(){let t={type:this.type,title:this.title,status:this.status};this.expose&&this.message&&this.message!==this.title&&(t.detail=this.message),this.instance!==void 0&&(t.instance=this.instance);for(let[o,r]of Object.entries(this.extensions))V.includes(o)||(t[o]=r);return t}toResponse(){return new Response(JSON.stringify(this.toJSON()),{status:this.status,headers:{"content-type":x,...this.headers}})}},Q=e=>e instanceof p||typeof e=="object"&&e!==null&&e[Symbol.for(w)]===!0;function j(e,t,o){return new p(e,t,o)}export{p as HttpError,x as PROBLEM_JSON,a as Reason,c as Status,u as Unofficial,F as allCodes,g as category,M as code,j as createError,Y as info,O as isCacheable,R as isClientError,C as isEmptyBody,S as isError,Q as isHttpError,A as isInformational,_ as isKnown,T as isOfficial,k as isRedirect,q as isRedirectWithBody,D as isRedirection,m as isRetryable,v as isServerError,P as isSuccess,U as isValid,y as reason};