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