@fastify-utils/error 0.0.0-stage → 1.0.1

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.
package/out/index.mjs ADDED
@@ -0,0 +1,803 @@
1
+ //#region src/core/http-error.ts
2
+ var HttpError = class extends Error {
3
+ type;
4
+ title;
5
+ status;
6
+ detail;
7
+ instance;
8
+ constructor(params) {
9
+ super(params.detail, { cause: params.cause });
10
+ this.name = "HttpError";
11
+ this.type = params.type;
12
+ this.title = params.title;
13
+ this.status = params.status;
14
+ this.detail = params.detail;
15
+ this.instance = params.instance;
16
+ Error.captureStackTrace(this, this.constructor);
17
+ }
18
+ toJSON() {
19
+ return {
20
+ type: this.type,
21
+ title: this.title,
22
+ status: this.status,
23
+ detail: this.detail,
24
+ ...this.instance && { instance: this.instance }
25
+ };
26
+ }
27
+ };
28
+ //#endregion
29
+ //#region src/errors/server/bad-gateway-error.ts
30
+ var BadGatewayError = class extends HttpError {
31
+ service;
32
+ constructor(detail, service) {
33
+ super({
34
+ type: getErrorType("bad-gateway"),
35
+ title: "Bad Gateway",
36
+ status: 502,
37
+ detail: normalizeToString(detail),
38
+ cause: extractCause(detail)
39
+ });
40
+ this.name = "BadGatewayError";
41
+ this.service = service;
42
+ }
43
+ toJSON() {
44
+ return {
45
+ ...super.toJSON(),
46
+ ...this.service && { service: this.service }
47
+ };
48
+ }
49
+ };
50
+ //#endregion
51
+ //#region src/errors/server/factories.ts
52
+ const standardFactories$1 = {
53
+ internal: (detail) => new InternalServerError(detail),
54
+ notImplemented: (detail) => new NotImplementedError(detail),
55
+ badGateway: (detail, service) => new BadGatewayError(detail, service),
56
+ serviceUnavailable: (detail, retryAfter) => new ServiceUnavailableError(detail, retryAfter),
57
+ gatewayTimeout: (detail, service) => new GatewayTimeoutError(detail, service),
58
+ httpVersionNotSupported: (detail) => new HttpVersionNotSupportedError(detail),
59
+ variantAlsoNegotiates: (detail) => new VariantAlsoNegotiatesError(detail),
60
+ insufficientStorage: (detail) => new InsufficientStorageError(detail),
61
+ loopDetected: (detail) => new LoopDetectedError(detail),
62
+ notExtended: (detail) => new NotExtendedError(detail),
63
+ networkAuthenticationRequired: (detail) => new NetworkAuthenticationRequiredError(detail)
64
+ };
65
+ const aliases$1 = {
66
+ db: (detail) => standardFactories$1.serviceUnavailable(detail),
67
+ fetch: (detail, service) => standardFactories$1.badGateway(detail, service),
68
+ envNotSet: (detail) => standardFactories$1.notImplemented(detail),
69
+ envInvalid: (detail) => standardFactories$1.notImplemented(detail),
70
+ maintenance: (detail, retryAfter) => standardFactories$1.serviceUnavailable(detail, retryAfter),
71
+ migration: (detail) => standardFactories$1.insufficientStorage(detail),
72
+ unhandledRejection: (detail) => standardFactories$1.internal(detail),
73
+ uncaughtException: (detail) => standardFactories$1.internal(detail)
74
+ };
75
+ const factories$1 = {
76
+ ...standardFactories$1,
77
+ ...aliases$1
78
+ };
79
+ //#endregion
80
+ //#region src/errors/server/gateway-timeout-error.ts
81
+ var GatewayTimeoutError = class extends HttpError {
82
+ service;
83
+ constructor(detail, service) {
84
+ super({
85
+ type: getErrorType("gateway-timeout"),
86
+ title: "Gateway Timeout",
87
+ status: 504,
88
+ detail: normalizeToString(detail),
89
+ cause: extractCause(detail)
90
+ });
91
+ this.name = "GatewayTimeoutError";
92
+ this.service = service;
93
+ }
94
+ toJSON() {
95
+ return {
96
+ ...super.toJSON(),
97
+ ...this.service && { service: this.service }
98
+ };
99
+ }
100
+ };
101
+ //#endregion
102
+ //#region src/errors/server/http-version-not-supported-error.ts
103
+ var HttpVersionNotSupportedError = class extends HttpError {
104
+ constructor(detail) {
105
+ super({
106
+ type: getErrorType("http-version-not-supported"),
107
+ title: "HTTP Version Not Supported",
108
+ status: 505,
109
+ detail: normalizeToString(detail),
110
+ cause: extractCause(detail)
111
+ });
112
+ this.name = "HttpVersionNotSupportedError";
113
+ }
114
+ };
115
+ //#endregion
116
+ //#region src/errors/server/insufficient-storage-error.ts
117
+ var InsufficientStorageError = class extends HttpError {
118
+ constructor(detail) {
119
+ super({
120
+ type: getErrorType("insufficient-storage"),
121
+ title: "Insufficient Storage",
122
+ status: 507,
123
+ detail: normalizeToString(detail),
124
+ cause: extractCause(detail)
125
+ });
126
+ this.name = "InsufficientStorageError";
127
+ }
128
+ };
129
+ //#endregion
130
+ //#region src/errors/server/internal-server-error.ts
131
+ var InternalServerError = class extends HttpError {
132
+ constructor(detail) {
133
+ super({
134
+ type: getErrorType("internal-server-error"),
135
+ title: "Internal Server Error",
136
+ status: 500,
137
+ detail: normalizeToString(detail),
138
+ cause: extractCause(detail)
139
+ });
140
+ this.name = "InternalServerError";
141
+ }
142
+ };
143
+ //#endregion
144
+ //#region src/errors/server/loop-detected-error.ts
145
+ var LoopDetectedError = class extends HttpError {
146
+ constructor(detail) {
147
+ super({
148
+ type: getErrorType("loop-detected"),
149
+ title: "Loop Detected",
150
+ status: 508,
151
+ detail: normalizeToString(detail),
152
+ cause: extractCause(detail)
153
+ });
154
+ this.name = "LoopDetectedError";
155
+ }
156
+ };
157
+ //#endregion
158
+ //#region src/errors/server/network-authentication-required-error.ts
159
+ var NetworkAuthenticationRequiredError = class extends HttpError {
160
+ constructor(detail) {
161
+ super({
162
+ type: getErrorType("network-authentication-required"),
163
+ title: "Network Authentication Required",
164
+ status: 511,
165
+ detail: normalizeToString(detail),
166
+ cause: extractCause(detail)
167
+ });
168
+ this.name = "NetworkAuthenticationRequiredError";
169
+ }
170
+ };
171
+ //#endregion
172
+ //#region src/errors/server/not-extended-error.ts
173
+ var NotExtendedError = class extends HttpError {
174
+ constructor(detail) {
175
+ super({
176
+ type: getErrorType("not-extended"),
177
+ title: "Not Extended",
178
+ status: 510,
179
+ detail: normalizeToString(detail),
180
+ cause: extractCause(detail)
181
+ });
182
+ this.name = "NotExtendedError";
183
+ }
184
+ };
185
+ //#endregion
186
+ //#region src/errors/server/not-implemented-error.ts
187
+ var NotImplementedError = class extends HttpError {
188
+ constructor(detail) {
189
+ super({
190
+ type: getErrorType("not-implemented"),
191
+ title: "Not Implemented",
192
+ status: 501,
193
+ detail: normalizeToString(detail),
194
+ cause: extractCause(detail)
195
+ });
196
+ this.name = "NotImplementedError";
197
+ }
198
+ };
199
+ //#endregion
200
+ //#region src/errors/server/service-unavailable-error.ts
201
+ var ServiceUnavailableError = class extends HttpError {
202
+ retryAfter;
203
+ constructor(detail, retryAfter) {
204
+ super({
205
+ type: getErrorType("service-unavailable"),
206
+ title: "Service Unavailable",
207
+ status: 503,
208
+ detail: normalizeToString(detail),
209
+ cause: extractCause(detail)
210
+ });
211
+ this.name = "ServiceUnavailableError";
212
+ this.retryAfter = retryAfter;
213
+ }
214
+ toJSON() {
215
+ return {
216
+ ...super.toJSON(),
217
+ ...this.retryAfter !== void 0 && { retryAfter: this.retryAfter }
218
+ };
219
+ }
220
+ };
221
+ //#endregion
222
+ //#region src/errors/server/variant-also-negotiates-error.ts
223
+ var VariantAlsoNegotiatesError = class extends HttpError {
224
+ constructor(detail) {
225
+ super({
226
+ type: getErrorType("variant-also-negotiates"),
227
+ title: "Variant Also Negotiates",
228
+ status: 506,
229
+ detail: normalizeToString(detail),
230
+ cause: extractCause(detail)
231
+ });
232
+ this.name = "VariantAlsoNegotiatesError";
233
+ }
234
+ };
235
+ //#endregion
236
+ //#region src/helpers/create-error-by-status/index.ts
237
+ const createErrorByStatus = (status, detail) => {
238
+ switch (status) {
239
+ case 400: return factories.badRequest(detail);
240
+ case 401: return factories.authentication(detail);
241
+ case 402: return factories.paymentRequired(detail);
242
+ case 403: return factories.authorization(detail);
243
+ case 404: return factories.notFound(detail);
244
+ case 405: return factories.methodNotAllowed(detail);
245
+ case 406: return factories.notAcceptable(detail);
246
+ case 407: return factories.proxyAuthenticationRequired(detail);
247
+ case 408: return factories.requestTimeout(detail);
248
+ case 409: return factories.conflict(detail);
249
+ case 410: return factories.gone(detail);
250
+ case 411: return factories.lengthRequired(detail);
251
+ case 412: return factories.preconditionFailed(detail);
252
+ case 413: return factories.payloadTooLarge(detail);
253
+ case 414: return factories.uriTooLong(detail);
254
+ case 415: return factories.unsupportedMediaType(detail);
255
+ case 416: return factories.rangeNotSatisfiable(detail);
256
+ case 417: return factories.expectationFailed(detail);
257
+ case 421: return factories.misdirectedRequest(detail);
258
+ case 422: return factories.validation(detail);
259
+ case 423: return factories.locked(detail);
260
+ case 424: return factories.failedDependency(detail);
261
+ case 425: return factories.tooEarly(detail);
262
+ case 426: return factories.upgradeRequired(detail);
263
+ case 428: return factories.preconditionRequired(detail);
264
+ case 429: return factories.rateLimit(detail);
265
+ case 431: return factories.requestHeaderFieldsTooLarge(detail);
266
+ case 451: return factories.unavailableForLegalReasons(detail);
267
+ case 500: return factories$1.internal(detail);
268
+ case 501: return factories$1.notImplemented(detail);
269
+ case 502: return factories$1.badGateway(detail);
270
+ case 503: return factories$1.serviceUnavailable(detail);
271
+ case 504: return factories$1.gatewayTimeout(detail);
272
+ case 505: return factories$1.httpVersionNotSupported(detail);
273
+ case 506: return factories$1.variantAlsoNegotiates(detail);
274
+ case 507: return factories$1.insufficientStorage(detail);
275
+ case 508: return factories$1.loopDetected(detail);
276
+ case 510: return factories$1.notExtended(detail);
277
+ case 511: return factories$1.networkAuthenticationRequired(detail);
278
+ default:
279
+ if (status >= 400 && status < 500) return factories.badRequest(detail);
280
+ return factories$1.internal(detail);
281
+ }
282
+ };
283
+ //#endregion
284
+ //#region src/helpers/extract-cause/index.ts
285
+ function extractCause(value) {
286
+ if (value instanceof Error) return value;
287
+ }
288
+ const currentConfig = { baseUrl: process.env.RFC9457_BASE_URL ?? "about:blank" };
289
+ //#endregion
290
+ //#region src/config/get-config.ts
291
+ function getConfig() {
292
+ return currentConfig;
293
+ }
294
+ //#endregion
295
+ //#region src/helpers/get-error-type/index.ts
296
+ function getErrorType(name) {
297
+ const baseUrl = getConfig().baseUrl ?? "about:blank";
298
+ if (baseUrl === "about:blank") return `${baseUrl}#${name}`;
299
+ return `${baseUrl}/${name}`;
300
+ }
301
+ //#endregion
302
+ //#region src/helpers/is-http-error/index.ts
303
+ function isHttpError(error) {
304
+ return error instanceof HttpError;
305
+ }
306
+ //#endregion
307
+ //#region src/helpers/is-valid-rfc9457-json/index.ts
308
+ const isValidRFC9457Json = (data) => {
309
+ if (!data || typeof data !== "object") return false;
310
+ const obj = data;
311
+ return "type" in obj && "title" in obj && "status" in obj && "detail" in obj;
312
+ };
313
+ //#endregion
314
+ //#region src/helpers/normalize-to-string/index.ts
315
+ function normalizeToString(value) {
316
+ if (value instanceof Error) return value.message;
317
+ if (typeof value === "string") return value;
318
+ if (value === null || value === void 0) return "Unknown error";
319
+ if (typeof value === "object") try {
320
+ return JSON.stringify(value);
321
+ } catch {
322
+ return String(value);
323
+ }
324
+ return String(value);
325
+ }
326
+ //#endregion
327
+ //#region src/errors/client/authentication-error.ts
328
+ var AuthenticationError = class extends HttpError {
329
+ constructor(detail) {
330
+ super({
331
+ type: getErrorType("authentication"),
332
+ title: "Authentication Required",
333
+ status: 401,
334
+ detail: normalizeToString(detail),
335
+ cause: extractCause(detail)
336
+ });
337
+ this.name = "AuthenticationError";
338
+ }
339
+ };
340
+ //#endregion
341
+ //#region src/errors/client/authorization-error.ts
342
+ var AuthorizationError = class extends HttpError {
343
+ constructor(detail) {
344
+ super({
345
+ type: getErrorType("authorization"),
346
+ title: "Forbidden",
347
+ status: 403,
348
+ detail: normalizeToString(detail),
349
+ cause: extractCause(detail)
350
+ });
351
+ this.name = "AuthorizationError";
352
+ }
353
+ };
354
+ //#endregion
355
+ //#region src/errors/client/bad-request-error.ts
356
+ var BadRequestError = class extends HttpError {
357
+ constructor(detail) {
358
+ super({
359
+ type: getErrorType("bad-request"),
360
+ title: "Bad Request",
361
+ status: 400,
362
+ detail: normalizeToString(detail),
363
+ cause: extractCause(detail)
364
+ });
365
+ this.name = "BadRequestError";
366
+ }
367
+ };
368
+ //#endregion
369
+ //#region src/errors/client/conflict-error.ts
370
+ var ConflictError = class extends HttpError {
371
+ constructor(detail) {
372
+ super({
373
+ type: getErrorType("conflict"),
374
+ title: "Conflict",
375
+ status: 409,
376
+ detail: normalizeToString(detail),
377
+ cause: extractCause(detail)
378
+ });
379
+ this.name = "ConflictError";
380
+ }
381
+ };
382
+ //#endregion
383
+ //#region src/errors/client/expectation-failed-error.ts
384
+ var ExpectationFailedError = class extends HttpError {
385
+ constructor(detail) {
386
+ super({
387
+ type: getErrorType("expectation-failed"),
388
+ title: "Expectation Failed",
389
+ status: 417,
390
+ detail: normalizeToString(detail),
391
+ cause: extractCause(detail)
392
+ });
393
+ this.name = "ExpectationFailedError";
394
+ }
395
+ };
396
+ //#endregion
397
+ //#region src/errors/client/factories.ts
398
+ const standardFactories = {
399
+ badRequest: (detail) => new BadRequestError(detail),
400
+ paymentRequired: (detail) => new PaymentRequiredError(detail),
401
+ authentication: (detail) => new AuthenticationError(detail),
402
+ authorization: (detail) => new AuthorizationError(detail),
403
+ notFound: (resourceOrDetail, id) => new NotFoundError(resourceOrDetail, id),
404
+ methodNotAllowed: (detail) => new MethodNotAllowedError(detail),
405
+ notAcceptable: (detail) => new NotAcceptableError(detail),
406
+ proxyAuthenticationRequired: (detail) => new ProxyAuthenticationRequiredError(detail),
407
+ requestTimeout: (detail) => new RequestTimeoutError(detail),
408
+ conflict: (detail) => new ConflictError(detail),
409
+ gone: (detail) => new GoneError(detail),
410
+ lengthRequired: (detail) => new LengthRequiredError(detail),
411
+ preconditionFailed: (detail) => new PreconditionFailedError(detail),
412
+ payloadTooLarge: (detail, maxSize) => new PayloadTooLargeError(detail, maxSize),
413
+ uriTooLong: (detail) => new UriTooLongError(detail),
414
+ unsupportedMediaType: (detail) => new UnsupportedMediaTypeError(detail),
415
+ rangeNotSatisfiable: (detail) => new RangeNotSatisfiableError(detail),
416
+ expectationFailed: (detail) => new ExpectationFailedError(detail),
417
+ misdirectedRequest: (detail) => new MisdirectedRequestError(detail),
418
+ validation: (detail, validationErrors) => new ValidationError(detail, validationErrors),
419
+ locked: (detail) => new LockedError(detail),
420
+ failedDependency: (detail) => new FailedDependencyError(detail),
421
+ tooEarly: (detail) => new TooEarlyError(detail),
422
+ upgradeRequired: (detail) => new UpgradeRequiredError(detail),
423
+ preconditionRequired: (detail) => new PreconditionRequiredError(detail),
424
+ rateLimit: (detail, retryAfter) => new RateLimitError(detail, retryAfter),
425
+ requestHeaderFieldsTooLarge: (detail) => new RequestHeaderFieldsTooLargeError(detail),
426
+ unavailableForLegalReasons: (detail) => new UnavailableForLegalReasonsError(detail)
427
+ };
428
+ const aliases = {
429
+ validate: (detail, validationErrors) => standardFactories.validation(detail, validationErrors),
430
+ permission: (detail) => standardFactories.authorization(detail),
431
+ access: (detail) => standardFactories.authorization(detail),
432
+ idNotFound: (resourceOrDetail, id) => standardFactories.notFound(resourceOrDetail, id),
433
+ duplicate: (detail) => standardFactories.conflict(detail),
434
+ thirdParty: (detail) => standardFactories.failedDependency(detail)
435
+ };
436
+ const factories = {
437
+ ...standardFactories,
438
+ ...aliases
439
+ };
440
+ //#endregion
441
+ //#region src/errors/client/failed-dependency-error.ts
442
+ var FailedDependencyError = class extends HttpError {
443
+ constructor(detail) {
444
+ super({
445
+ type: getErrorType("failed-dependency"),
446
+ title: "Failed Dependency",
447
+ status: 424,
448
+ detail: normalizeToString(detail),
449
+ cause: extractCause(detail)
450
+ });
451
+ this.name = "FailedDependencyError";
452
+ }
453
+ };
454
+ //#endregion
455
+ //#region src/errors/client/gone-error.ts
456
+ var GoneError = class extends HttpError {
457
+ constructor(detail) {
458
+ super({
459
+ type: getErrorType("gone"),
460
+ title: "Gone",
461
+ status: 410,
462
+ detail: normalizeToString(detail),
463
+ cause: extractCause(detail)
464
+ });
465
+ this.name = "GoneError";
466
+ }
467
+ };
468
+ //#endregion
469
+ //#region src/errors/client/length-required-error.ts
470
+ var LengthRequiredError = class extends HttpError {
471
+ constructor(detail) {
472
+ super({
473
+ type: getErrorType("length-required"),
474
+ title: "Length Required",
475
+ status: 411,
476
+ detail: normalizeToString(detail),
477
+ cause: extractCause(detail)
478
+ });
479
+ this.name = "LengthRequiredError";
480
+ }
481
+ };
482
+ //#endregion
483
+ //#region src/errors/client/locked-error.ts
484
+ var LockedError = class extends HttpError {
485
+ constructor(detail) {
486
+ super({
487
+ type: getErrorType("locked"),
488
+ title: "Locked",
489
+ status: 423,
490
+ detail: normalizeToString(detail),
491
+ cause: extractCause(detail)
492
+ });
493
+ this.name = "LockedError";
494
+ }
495
+ };
496
+ //#endregion
497
+ //#region src/errors/client/method-not-allowed-error.ts
498
+ var MethodNotAllowedError = class extends HttpError {
499
+ constructor(detail) {
500
+ super({
501
+ type: getErrorType("method-not-allowed"),
502
+ title: "Method Not Allowed",
503
+ status: 405,
504
+ detail: normalizeToString(detail),
505
+ cause: extractCause(detail)
506
+ });
507
+ this.name = "MethodNotAllowedError";
508
+ }
509
+ };
510
+ //#endregion
511
+ //#region src/errors/client/misdirected-request-error.ts
512
+ var MisdirectedRequestError = class extends HttpError {
513
+ constructor(detail) {
514
+ super({
515
+ type: getErrorType("misdirected-request"),
516
+ title: "Misdirected Request",
517
+ status: 421,
518
+ detail: normalizeToString(detail),
519
+ cause: extractCause(detail)
520
+ });
521
+ this.name = "MisdirectedRequestError";
522
+ }
523
+ };
524
+ //#endregion
525
+ //#region src/errors/client/not-acceptable-error.ts
526
+ var NotAcceptableError = class extends HttpError {
527
+ constructor(detail) {
528
+ super({
529
+ type: getErrorType("not-acceptable"),
530
+ title: "Not Acceptable",
531
+ status: 406,
532
+ detail: normalizeToString(detail),
533
+ cause: extractCause(detail)
534
+ });
535
+ this.name = "NotAcceptableError";
536
+ }
537
+ };
538
+ //#endregion
539
+ //#region src/errors/client/not-found-error.ts
540
+ var NotFoundError = class extends HttpError {
541
+ constructor(resourceOrDetail, id) {
542
+ let detail;
543
+ if (id === void 0) detail = normalizeToString(resourceOrDetail);
544
+ else detail = `${String(resourceOrDetail)} ${id} not found`;
545
+ super({
546
+ type: getErrorType("not-found"),
547
+ title: "Not Found",
548
+ status: 404,
549
+ detail,
550
+ cause: id === void 0 ? extractCause(resourceOrDetail) : void 0
551
+ });
552
+ this.name = "NotFoundError";
553
+ }
554
+ };
555
+ //#endregion
556
+ //#region src/errors/client/payload-too-large-error.ts
557
+ var PayloadTooLargeError = class extends HttpError {
558
+ maxSize;
559
+ constructor(detail, maxSize) {
560
+ super({
561
+ type: getErrorType("payload-too-large"),
562
+ title: "Payload Too Large",
563
+ status: 413,
564
+ detail: normalizeToString(detail),
565
+ cause: extractCause(detail)
566
+ });
567
+ this.name = "PayloadTooLargeError";
568
+ this.maxSize = maxSize;
569
+ }
570
+ toJSON() {
571
+ return {
572
+ ...super.toJSON(),
573
+ ...this.maxSize !== void 0 && { maxSize: this.maxSize }
574
+ };
575
+ }
576
+ };
577
+ //#endregion
578
+ //#region src/errors/client/payment-required-error.ts
579
+ var PaymentRequiredError = class extends HttpError {
580
+ constructor(detail) {
581
+ super({
582
+ type: getErrorType("payment-required"),
583
+ title: "Payment Required",
584
+ status: 402,
585
+ detail: normalizeToString(detail),
586
+ cause: extractCause(detail)
587
+ });
588
+ this.name = "PaymentRequiredError";
589
+ }
590
+ };
591
+ //#endregion
592
+ //#region src/errors/client/precondition-failed-error.ts
593
+ var PreconditionFailedError = class extends HttpError {
594
+ constructor(detail) {
595
+ super({
596
+ type: getErrorType("precondition-failed"),
597
+ title: "Precondition Failed",
598
+ status: 412,
599
+ detail: normalizeToString(detail),
600
+ cause: extractCause(detail)
601
+ });
602
+ this.name = "PreconditionFailedError";
603
+ }
604
+ };
605
+ //#endregion
606
+ //#region src/errors/client/precondition-required-error.ts
607
+ var PreconditionRequiredError = class extends HttpError {
608
+ constructor(detail) {
609
+ super({
610
+ type: getErrorType("precondition-required"),
611
+ title: "Precondition Required",
612
+ status: 428,
613
+ detail: normalizeToString(detail),
614
+ cause: extractCause(detail)
615
+ });
616
+ this.name = "PreconditionRequiredError";
617
+ }
618
+ };
619
+ //#endregion
620
+ //#region src/errors/client/proxy-authentication-required-error.ts
621
+ var ProxyAuthenticationRequiredError = class extends HttpError {
622
+ constructor(detail) {
623
+ super({
624
+ type: getErrorType("proxy-authentication-required"),
625
+ title: "Proxy Authentication Required",
626
+ status: 407,
627
+ detail: normalizeToString(detail),
628
+ cause: extractCause(detail)
629
+ });
630
+ this.name = "ProxyAuthenticationRequiredError";
631
+ }
632
+ };
633
+ //#endregion
634
+ //#region src/errors/client/range-not-satisfiable-error.ts
635
+ var RangeNotSatisfiableError = class extends HttpError {
636
+ constructor(detail) {
637
+ super({
638
+ type: getErrorType("range-not-satisfiable"),
639
+ title: "Range Not Satisfiable",
640
+ status: 416,
641
+ detail: normalizeToString(detail),
642
+ cause: extractCause(detail)
643
+ });
644
+ this.name = "RangeNotSatisfiableError";
645
+ }
646
+ };
647
+ //#endregion
648
+ //#region src/errors/client/rate-limit-error.ts
649
+ var RateLimitError = class extends HttpError {
650
+ retryAfter;
651
+ constructor(detail, retryAfter) {
652
+ super({
653
+ type: getErrorType("rate-limit"),
654
+ title: "Too Many Requests",
655
+ status: 429,
656
+ detail: normalizeToString(detail),
657
+ cause: extractCause(detail)
658
+ });
659
+ this.name = "RateLimitError";
660
+ this.retryAfter = retryAfter;
661
+ }
662
+ toJSON() {
663
+ return {
664
+ ...super.toJSON(),
665
+ ...this.retryAfter !== void 0 && { retryAfter: this.retryAfter }
666
+ };
667
+ }
668
+ };
669
+ //#endregion
670
+ //#region src/errors/client/request-header-fields-too-large-error.ts
671
+ var RequestHeaderFieldsTooLargeError = class extends HttpError {
672
+ constructor(detail) {
673
+ super({
674
+ type: getErrorType("request-header-fields-too-large"),
675
+ title: "Request Header Fields Too Large",
676
+ status: 431,
677
+ detail: normalizeToString(detail),
678
+ cause: extractCause(detail)
679
+ });
680
+ this.name = "RequestHeaderFieldsTooLargeError";
681
+ }
682
+ };
683
+ //#endregion
684
+ //#region src/errors/client/request-timeout-error.ts
685
+ var RequestTimeoutError = class extends HttpError {
686
+ constructor(detail) {
687
+ super({
688
+ type: getErrorType("request-timeout"),
689
+ title: "Request Timeout",
690
+ status: 408,
691
+ detail: normalizeToString(detail),
692
+ cause: extractCause(detail)
693
+ });
694
+ this.name = "RequestTimeoutError";
695
+ }
696
+ };
697
+ //#endregion
698
+ //#region src/errors/client/too-early-error.ts
699
+ var TooEarlyError = class extends HttpError {
700
+ constructor(detail) {
701
+ super({
702
+ type: getErrorType("too-early"),
703
+ title: "Too Early",
704
+ status: 425,
705
+ detail: normalizeToString(detail),
706
+ cause: extractCause(detail)
707
+ });
708
+ this.name = "TooEarlyError";
709
+ }
710
+ };
711
+ //#endregion
712
+ //#region src/errors/client/unavailable-for-legal-reasons-error.ts
713
+ var UnavailableForLegalReasonsError = class extends HttpError {
714
+ constructor(detail) {
715
+ super({
716
+ type: getErrorType("unavailable-for-legal-reasons"),
717
+ title: "Unavailable For Legal Reasons",
718
+ status: 451,
719
+ detail: normalizeToString(detail),
720
+ cause: extractCause(detail)
721
+ });
722
+ this.name = "UnavailableForLegalReasonsError";
723
+ }
724
+ };
725
+ //#endregion
726
+ //#region src/errors/client/unsupported-media-type-error.ts
727
+ var UnsupportedMediaTypeError = class extends HttpError {
728
+ constructor(detail) {
729
+ super({
730
+ type: getErrorType("unsupported-media-type"),
731
+ title: "Unsupported Media Type",
732
+ status: 415,
733
+ detail: normalizeToString(detail),
734
+ cause: extractCause(detail)
735
+ });
736
+ this.name = "UnsupportedMediaTypeError";
737
+ }
738
+ };
739
+ //#endregion
740
+ //#region src/errors/client/upgrade-required-error.ts
741
+ var UpgradeRequiredError = class extends HttpError {
742
+ constructor(detail) {
743
+ super({
744
+ type: getErrorType("upgrade-required"),
745
+ title: "Upgrade Required",
746
+ status: 426,
747
+ detail: normalizeToString(detail),
748
+ cause: extractCause(detail)
749
+ });
750
+ this.name = "UpgradeRequiredError";
751
+ }
752
+ };
753
+ //#endregion
754
+ //#region src/errors/client/uri-too-long-error.ts
755
+ var UriTooLongError = class extends HttpError {
756
+ constructor(detail) {
757
+ super({
758
+ type: getErrorType("uri-too-long"),
759
+ title: "URI Too Long",
760
+ status: 414,
761
+ detail: normalizeToString(detail),
762
+ cause: extractCause(detail)
763
+ });
764
+ this.name = "UriTooLongError";
765
+ }
766
+ };
767
+ //#endregion
768
+ //#region src/errors/client/validation-error.ts
769
+ var ValidationError = class extends HttpError {
770
+ validationErrors;
771
+ constructor(detail, validationErrors) {
772
+ super({
773
+ type: getErrorType("validation"),
774
+ title: "Validation Error",
775
+ status: 422,
776
+ detail: normalizeToString(detail),
777
+ cause: extractCause(detail)
778
+ });
779
+ this.name = "ValidationError";
780
+ this.validationErrors = validationErrors;
781
+ }
782
+ toJSON() {
783
+ return {
784
+ ...super.toJSON(),
785
+ ...this.validationErrors && { validationErrors: this.validationErrors }
786
+ };
787
+ }
788
+ };
789
+ //#endregion
790
+ //#region src/error.ts
791
+ const error = {
792
+ ...factories,
793
+ ...factories$1
794
+ };
795
+ //#endregion
796
+ //#region src/errors.ts
797
+ const errors = {
798
+ client: factories,
799
+ server: factories$1,
800
+ byStatus: createErrorByStatus
801
+ };
802
+ //#endregion
803
+ export { error, errors, isHttpError, isValidRFC9457Json };