@bombillazo/error-x 0.3.0 → 0.4.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/README.md +235 -370
- package/dist/index.cjs +511 -608
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +593 -680
- package/dist/index.d.ts +593 -680
- package/dist/index.js +511 -608
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3,16 +3,6 @@ import safeStringify from 'safe-stringify';
|
|
|
3
3
|
// src/error.ts
|
|
4
4
|
|
|
5
5
|
// src/types.ts
|
|
6
|
-
var HandlingTargets = /* @__PURE__ */ ((HandlingTargets2) => {
|
|
7
|
-
HandlingTargets2["MODAL"] = "modal";
|
|
8
|
-
HandlingTargets2["TOAST"] = "toast";
|
|
9
|
-
HandlingTargets2["INLINE"] = "inline";
|
|
10
|
-
HandlingTargets2["BANNER"] = "banner";
|
|
11
|
-
HandlingTargets2["CONSOLE"] = "console";
|
|
12
|
-
HandlingTargets2["LOGGER"] = "logger";
|
|
13
|
-
HandlingTargets2["NOTIFICATION"] = "notification";
|
|
14
|
-
return HandlingTargets2;
|
|
15
|
-
})(HandlingTargets || {});
|
|
16
6
|
var ERROR_X_OPTION_FIELDS = [
|
|
17
7
|
"message",
|
|
18
8
|
"name",
|
|
@@ -20,14 +10,18 @@ var ERROR_X_OPTION_FIELDS = [
|
|
|
20
10
|
"uiMessage",
|
|
21
11
|
"cause",
|
|
22
12
|
"metadata",
|
|
23
|
-
"actions",
|
|
24
13
|
"httpStatus",
|
|
25
|
-
"type"
|
|
14
|
+
"type",
|
|
15
|
+
"sourceUrl",
|
|
16
|
+
"docsUrl",
|
|
17
|
+
"source"
|
|
26
18
|
];
|
|
27
19
|
|
|
28
20
|
// src/error.ts
|
|
29
21
|
var acceptedFields = new Set(ERROR_X_OPTION_FIELDS);
|
|
30
22
|
var ErrorX = class _ErrorX extends Error {
|
|
23
|
+
/** Global configuration for all ErrorX instances */
|
|
24
|
+
static _config = null;
|
|
31
25
|
/** Error identifier code, auto-generated from name if not provided */
|
|
32
26
|
code;
|
|
33
27
|
/** User-friendly message suitable for display in UI */
|
|
@@ -36,73 +30,85 @@ var ErrorX = class _ErrorX extends Error {
|
|
|
36
30
|
metadata;
|
|
37
31
|
/** Timestamp when the error was created */
|
|
38
32
|
timestamp;
|
|
39
|
-
/** Error actions for UI behavior and handling */
|
|
40
|
-
actions;
|
|
41
33
|
/** HTTP status code (100-599) for HTTP-related errors */
|
|
42
34
|
httpStatus;
|
|
43
35
|
/** Error type for categorization */
|
|
44
36
|
type;
|
|
37
|
+
/** Source URL related to the error (API endpoint, page URL, resource URL) */
|
|
38
|
+
sourceUrl;
|
|
39
|
+
/** Documentation URL for this specific error */
|
|
40
|
+
docsUrl;
|
|
41
|
+
/** Where the error originated (service name, module, component) */
|
|
42
|
+
source;
|
|
43
|
+
/** Original error that caused this error (preserves error chain) */
|
|
44
|
+
cause;
|
|
45
45
|
/**
|
|
46
46
|
* Creates a new ErrorX instance with enhanced error handling capabilities.
|
|
47
47
|
*
|
|
48
|
-
* @param messageOrOptions - Error message string
|
|
49
|
-
* @param additionalOptions - Additional options when first parameter is a string (optional)
|
|
48
|
+
* @param messageOrOptions - Error message string or ErrorXOptions object (optional)
|
|
50
49
|
*
|
|
51
50
|
* @example
|
|
52
51
|
* ```typescript
|
|
52
|
+
* // Create with default message
|
|
53
|
+
* const error1 = new ErrorX()
|
|
54
|
+
*
|
|
53
55
|
* // Create with string message only
|
|
54
|
-
* const
|
|
56
|
+
* const error2 = new ErrorX('Database query failed')
|
|
55
57
|
*
|
|
56
|
-
* // Create with
|
|
57
|
-
* const
|
|
58
|
+
* // Create with options object
|
|
59
|
+
* const error3 = new ErrorX({
|
|
60
|
+
* message: 'Database query failed',
|
|
58
61
|
* name: 'DatabaseError',
|
|
59
62
|
* code: 'DB_QUERY_FAILED',
|
|
60
63
|
* uiMessage: 'Unable to load data. Please try again.',
|
|
61
64
|
* metadata: { query: 'SELECT * FROM users', timeout: 5000 }
|
|
62
65
|
* })
|
|
63
66
|
*
|
|
64
|
-
* //
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
* actions: [
|
|
70
|
-
* { action: 'notify', payload: { targets: [HandlingTargets.TOAST] } }
|
|
71
|
-
* ]
|
|
67
|
+
* // With type-safe metadata
|
|
68
|
+
* type MyMeta = { userId: number };
|
|
69
|
+
* const error4 = new ErrorX<MyMeta>({
|
|
70
|
+
* message: 'User action failed',
|
|
71
|
+
* metadata: { userId: 123 }
|
|
72
72
|
* })
|
|
73
73
|
*
|
|
74
|
-
* //
|
|
74
|
+
* // For converting unknown errors, use ErrorX.from()
|
|
75
75
|
* const apiError = { message: 'User not found', code: 404 }
|
|
76
|
-
* const
|
|
77
|
-
*
|
|
78
|
-
* // Create with no options (uses defaults)
|
|
79
|
-
* const error5 = new ErrorX()
|
|
76
|
+
* const error5 = ErrorX.from(apiError)
|
|
80
77
|
* ```
|
|
81
78
|
*/
|
|
82
|
-
constructor(messageOrOptions
|
|
79
|
+
constructor(messageOrOptions) {
|
|
83
80
|
let options = {};
|
|
84
81
|
if (typeof messageOrOptions === "string") {
|
|
85
|
-
options = {
|
|
86
|
-
message: messageOrOptions,
|
|
87
|
-
...additionalOptions
|
|
88
|
-
};
|
|
89
|
-
} else if (_ErrorX.isErrorXOptions(messageOrOptions)) {
|
|
90
|
-
options = messageOrOptions;
|
|
82
|
+
options = { message: messageOrOptions };
|
|
91
83
|
} else if (messageOrOptions != null) {
|
|
92
|
-
options =
|
|
84
|
+
options = messageOrOptions;
|
|
93
85
|
}
|
|
94
|
-
const
|
|
95
|
-
|
|
86
|
+
const envConfig = _ErrorX.getConfig();
|
|
87
|
+
const message = options.message?.trim() ? options.message : "An error occurred";
|
|
88
|
+
const convertedCause = _ErrorX.toErrorXCause(options.cause);
|
|
89
|
+
super(message);
|
|
90
|
+
this.cause = convertedCause;
|
|
96
91
|
this.name = options.name ?? _ErrorX.getDefaultName();
|
|
97
92
|
this.code = options.code != null ? String(options.code) : _ErrorX.generateDefaultCode(options.name);
|
|
98
93
|
this.uiMessage = options.uiMessage;
|
|
99
94
|
this.metadata = options.metadata;
|
|
100
|
-
this.actions = options.actions;
|
|
101
95
|
this.httpStatus = _ErrorX.validateHttpStatus(options.httpStatus);
|
|
102
96
|
this.type = _ErrorX.validateType(options.type);
|
|
103
97
|
this.timestamp = /* @__PURE__ */ new Date();
|
|
104
|
-
|
|
105
|
-
|
|
98
|
+
this.sourceUrl = options.sourceUrl;
|
|
99
|
+
this.source = options.source ?? envConfig?.source;
|
|
100
|
+
let generatedDocsUrl;
|
|
101
|
+
if (envConfig?.docsBaseURL && envConfig?.docsMap && this.code) {
|
|
102
|
+
const docPath = envConfig.docsMap[this.code];
|
|
103
|
+
if (docPath) {
|
|
104
|
+
const base = envConfig.docsBaseURL.replace(/\/+$/, "");
|
|
105
|
+
const path = docPath.replace(/^\/+/, "");
|
|
106
|
+
generatedDocsUrl = `${base}/${path}`;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
this.docsUrl = options.docsUrl ?? generatedDocsUrl;
|
|
110
|
+
if (convertedCause?.stack) {
|
|
111
|
+
this.stack = _ErrorX.preserveOriginalStackFromCause(convertedCause, this);
|
|
106
112
|
} else {
|
|
107
113
|
if (typeof Error.captureStackTrace === "function") {
|
|
108
114
|
Error.captureStackTrace(this, this.constructor);
|
|
@@ -117,6 +123,72 @@ var ErrorX = class _ErrorX extends Error {
|
|
|
117
123
|
static getDefaultName() {
|
|
118
124
|
return "Error";
|
|
119
125
|
}
|
|
126
|
+
/**
|
|
127
|
+
* Converts any value to ErrorXCause format.
|
|
128
|
+
* @param value - Value to convert to ErrorXCause
|
|
129
|
+
* @returns ErrorXCause object or undefined if value is null/undefined
|
|
130
|
+
*/
|
|
131
|
+
static toErrorXCause(value) {
|
|
132
|
+
if (value === void 0 || value === null) {
|
|
133
|
+
return void 0;
|
|
134
|
+
}
|
|
135
|
+
if (value instanceof Error) {
|
|
136
|
+
const cause = {
|
|
137
|
+
message: value.message
|
|
138
|
+
};
|
|
139
|
+
if (value.name) {
|
|
140
|
+
cause.name = value.name;
|
|
141
|
+
}
|
|
142
|
+
if (value.stack) {
|
|
143
|
+
cause.stack = value.stack;
|
|
144
|
+
}
|
|
145
|
+
return cause;
|
|
146
|
+
}
|
|
147
|
+
if (typeof value === "object") {
|
|
148
|
+
const obj = value;
|
|
149
|
+
const cause = {
|
|
150
|
+
message: String(obj.message || obj)
|
|
151
|
+
};
|
|
152
|
+
if (obj.name) {
|
|
153
|
+
cause.name = String(obj.name);
|
|
154
|
+
}
|
|
155
|
+
if (obj.stack) {
|
|
156
|
+
cause.stack = String(obj.stack);
|
|
157
|
+
}
|
|
158
|
+
return cause;
|
|
159
|
+
}
|
|
160
|
+
return {
|
|
161
|
+
message: String(value)
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Configure global ErrorX settings.
|
|
166
|
+
* This method allows you to set defaults for all ErrorX instances.
|
|
167
|
+
*
|
|
168
|
+
* @param config - Configuration object
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* ```typescript
|
|
172
|
+
* ErrorX.configure({
|
|
173
|
+
* source: 'my-api-service',
|
|
174
|
+
* docsBaseURL: 'https://docs.example.com/errors',
|
|
175
|
+
* docsMap: {
|
|
176
|
+
* 'AUTH_FAILED': 'authentication-errors',
|
|
177
|
+
* 'DB_ERROR': 'database-errors'
|
|
178
|
+
* }
|
|
179
|
+
* })
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
static configure(config) {
|
|
183
|
+
_ErrorX._config = { ..._ErrorX._config || {}, ...config };
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Get the current global configuration.
|
|
187
|
+
* Returns null if no configuration has been set.
|
|
188
|
+
*/
|
|
189
|
+
static getConfig() {
|
|
190
|
+
return _ErrorX._config;
|
|
191
|
+
}
|
|
120
192
|
/**
|
|
121
193
|
* Validates HTTP status code to ensure it's within valid range (100-599)
|
|
122
194
|
*
|
|
@@ -190,16 +262,16 @@ var ErrorX = class _ErrorX extends Error {
|
|
|
190
262
|
}
|
|
191
263
|
/**
|
|
192
264
|
* Preserves the original error's stack trace while updating the error message.
|
|
193
|
-
* Combines the new error's message with the original error's stack trace.
|
|
265
|
+
* Combines the new error's message with the original error's stack trace from ErrorXCause.
|
|
194
266
|
*
|
|
195
|
-
* @param
|
|
267
|
+
* @param cause - The ErrorXCause containing the original stack to preserve
|
|
196
268
|
* @param newError - The new error whose message to use
|
|
197
269
|
* @returns Combined stack trace with new error message and original stack
|
|
198
270
|
*/
|
|
199
|
-
static
|
|
200
|
-
if (!
|
|
271
|
+
static preserveOriginalStackFromCause(cause, newError) {
|
|
272
|
+
if (!cause.stack) return newError.stack || "";
|
|
201
273
|
const newErrorFirstLine = `${newError.name}: ${newError.message}`;
|
|
202
|
-
const originalStackLines =
|
|
274
|
+
const originalStackLines = cause.stack.split("\n");
|
|
203
275
|
const originalStackTrace = originalStackLines.slice(1);
|
|
204
276
|
return [newErrorFirstLine, ...originalStackTrace].join("\n");
|
|
205
277
|
}
|
|
@@ -212,10 +284,24 @@ var ErrorX = class _ErrorX extends Error {
|
|
|
212
284
|
*/
|
|
213
285
|
static cleanStack(stack) {
|
|
214
286
|
if (!stack) return "";
|
|
287
|
+
const config = _ErrorX.getConfig();
|
|
288
|
+
const cleanStackConfig = config?.cleanStack ?? true;
|
|
289
|
+
if (cleanStackConfig === false) {
|
|
290
|
+
return stack;
|
|
291
|
+
}
|
|
215
292
|
const stackLines = stack.split("\n");
|
|
216
293
|
const cleanedLines = [];
|
|
294
|
+
const defaultPatterns = [
|
|
295
|
+
"new ErrorX",
|
|
296
|
+
"ErrorX.constructor",
|
|
297
|
+
"ErrorX.from",
|
|
298
|
+
"error-x/dist/",
|
|
299
|
+
"error-x/src/error.ts"
|
|
300
|
+
];
|
|
301
|
+
const patterns = Array.isArray(cleanStackConfig) ? cleanStackConfig : defaultPatterns;
|
|
217
302
|
for (const line of stackLines) {
|
|
218
|
-
|
|
303
|
+
const shouldSkip = patterns.some((pattern) => line.includes(pattern));
|
|
304
|
+
if (shouldSkip) {
|
|
219
305
|
continue;
|
|
220
306
|
}
|
|
221
307
|
cleanedLines.push(line);
|
|
@@ -245,35 +331,6 @@ var ErrorX = class _ErrorX extends Error {
|
|
|
245
331
|
}
|
|
246
332
|
return stack;
|
|
247
333
|
}
|
|
248
|
-
/**
|
|
249
|
-
* Formats error messages with proper capitalization and punctuation.
|
|
250
|
-
* Ensures consistent message formatting across all ErrorX instances.
|
|
251
|
-
*
|
|
252
|
-
* @param message - Raw error message to format (optional)
|
|
253
|
-
* @returns Formatted message with proper capitalization and punctuation
|
|
254
|
-
*
|
|
255
|
-
* @example
|
|
256
|
-
* ```typescript
|
|
257
|
-
* formatMessage('database connection failed') // 'Database connection failed.'
|
|
258
|
-
* formatMessage('user not found. please check credentials') // 'User not found. Please check credentials.'
|
|
259
|
-
* formatMessage() // 'An error occurred'
|
|
260
|
-
* ```
|
|
261
|
-
*/
|
|
262
|
-
static formatMessage(message) {
|
|
263
|
-
if (!message || typeof message !== "string" || !message.trim()) {
|
|
264
|
-
return "An error occurred";
|
|
265
|
-
}
|
|
266
|
-
let formatted = message.split(". ").map((sentence) => {
|
|
267
|
-
const trimmed = sentence.trim();
|
|
268
|
-
if (!trimmed) return trimmed;
|
|
269
|
-
return trimmed.charAt(0).toUpperCase() + trimmed.slice(1);
|
|
270
|
-
}).join(". ");
|
|
271
|
-
const endsWithPunctuation = /[.!?)\]]$/.test(formatted);
|
|
272
|
-
if (!endsWithPunctuation) {
|
|
273
|
-
formatted = `${formatted}.`;
|
|
274
|
-
}
|
|
275
|
-
return formatted;
|
|
276
|
-
}
|
|
277
334
|
/**
|
|
278
335
|
* Creates a new ErrorX instance with additional metadata merged with existing metadata.
|
|
279
336
|
* The original error properties are preserved while extending the metadata.
|
|
@@ -304,15 +361,16 @@ var ErrorX = class _ErrorX extends Error {
|
|
|
304
361
|
cause: this.cause,
|
|
305
362
|
metadata: { ...this.metadata ?? {}, ...additionalMetadata },
|
|
306
363
|
httpStatus: this.httpStatus,
|
|
307
|
-
type: this.type
|
|
364
|
+
type: this.type,
|
|
365
|
+
sourceUrl: this.sourceUrl,
|
|
366
|
+
docsUrl: this.docsUrl,
|
|
367
|
+
source: this.source
|
|
308
368
|
};
|
|
309
|
-
if (this.actions) {
|
|
310
|
-
options.actions = this.actions;
|
|
311
|
-
}
|
|
312
369
|
const newError = new _ErrorX(options);
|
|
313
370
|
if (this.stack) {
|
|
314
371
|
newError.stack = this.stack;
|
|
315
372
|
}
|
|
373
|
+
newError.timestamp = this.timestamp;
|
|
316
374
|
return newError;
|
|
317
375
|
}
|
|
318
376
|
/**
|
|
@@ -352,9 +410,11 @@ var ErrorX = class _ErrorX extends Error {
|
|
|
352
410
|
let uiMessage = "";
|
|
353
411
|
let cause;
|
|
354
412
|
let metadata = {};
|
|
355
|
-
let actions;
|
|
356
413
|
let httpStatus;
|
|
357
414
|
let type;
|
|
415
|
+
let url;
|
|
416
|
+
let href;
|
|
417
|
+
let source;
|
|
358
418
|
if (error) {
|
|
359
419
|
if (typeof error === "string") {
|
|
360
420
|
message = error;
|
|
@@ -377,9 +437,6 @@ var ErrorX = class _ErrorX extends Error {
|
|
|
377
437
|
if ("code" in error && error.code) code = String(error.code);
|
|
378
438
|
if ("uiMessage" in error && error.uiMessage) uiMessage = String(error.uiMessage);
|
|
379
439
|
else if ("userMessage" in error && error.userMessage) uiMessage = String(error.userMessage);
|
|
380
|
-
if ("actions" in error && Array.isArray(error.actions)) {
|
|
381
|
-
actions = error.actions;
|
|
382
|
-
}
|
|
383
440
|
let _httpStatus;
|
|
384
441
|
if ("httpStatus" in error) {
|
|
385
442
|
_httpStatus = error.httpStatus;
|
|
@@ -395,6 +452,25 @@ var ErrorX = class _ErrorX extends Error {
|
|
|
395
452
|
if ("type" in error && error.type) {
|
|
396
453
|
type = _ErrorX.validateType(String(error.type));
|
|
397
454
|
}
|
|
455
|
+
if ("sourceUrl" in error && error.sourceUrl) {
|
|
456
|
+
url = String(error.sourceUrl);
|
|
457
|
+
} else if ("url" in error && error.url) {
|
|
458
|
+
url = String(error.url);
|
|
459
|
+
}
|
|
460
|
+
if ("docsUrl" in error && error.docsUrl) {
|
|
461
|
+
href = String(error.docsUrl);
|
|
462
|
+
} else if ("href" in error && error.href) {
|
|
463
|
+
href = String(error.href);
|
|
464
|
+
} else if ("documentationUrl" in error && error.documentationUrl) {
|
|
465
|
+
href = String(error.documentationUrl);
|
|
466
|
+
}
|
|
467
|
+
if ("source" in error && error.source) {
|
|
468
|
+
source = String(error.source);
|
|
469
|
+
} else if ("service" in error && error.service) {
|
|
470
|
+
source = String(error.service);
|
|
471
|
+
} else if ("component" in error && error.component) {
|
|
472
|
+
source = String(error.component);
|
|
473
|
+
}
|
|
398
474
|
metadata = { originalError: error };
|
|
399
475
|
}
|
|
400
476
|
}
|
|
@@ -406,58 +482,18 @@ var ErrorX = class _ErrorX extends Error {
|
|
|
406
482
|
if (uiMessage) options.uiMessage = uiMessage;
|
|
407
483
|
if (cause) options.cause = cause;
|
|
408
484
|
if (Object.keys(metadata).length > 0) options.metadata = metadata;
|
|
409
|
-
if (actions && actions.length > 0) options.actions = actions;
|
|
410
485
|
if (httpStatus) options.httpStatus = httpStatus;
|
|
411
486
|
if (type) options.type = type;
|
|
487
|
+
if (url) options.sourceUrl = url;
|
|
488
|
+
if (href) options.docsUrl = href;
|
|
489
|
+
if (source) options.source = source;
|
|
412
490
|
return options;
|
|
413
491
|
}
|
|
414
|
-
|
|
415
|
-
* Converts unknown input into an ErrorX instance with intelligent property extraction.
|
|
416
|
-
* Handles strings, regular Error objects, API response objects, and unknown values.
|
|
417
|
-
*
|
|
418
|
-
* @param error - Value to convert to ErrorX
|
|
419
|
-
* @returns ErrorX instance with extracted properties
|
|
420
|
-
*
|
|
421
|
-
* @example
|
|
422
|
-
* ```typescript
|
|
423
|
-
* // Convert string error
|
|
424
|
-
* const error1 = ErrorX.toErrorX('Something went wrong')
|
|
425
|
-
*
|
|
426
|
-
* // Convert regular Error
|
|
427
|
-
* const error2 = ErrorX.toErrorX(new Error('Database failed'))
|
|
428
|
-
*
|
|
429
|
-
* // Convert API response object
|
|
430
|
-
* const apiError = {
|
|
431
|
-
* message: 'User not found',
|
|
432
|
-
* code: 'USER_404',
|
|
433
|
-
* statusText: 'Not Found'
|
|
434
|
-
* }
|
|
435
|
-
* const error3 = ErrorX.toErrorX(apiError)
|
|
436
|
-
* ```
|
|
437
|
-
*/
|
|
438
|
-
static toErrorX(error) {
|
|
492
|
+
static from(error) {
|
|
439
493
|
if (error instanceof _ErrorX) return error;
|
|
440
494
|
const options = _ErrorX.convertUnknownToOptions(error);
|
|
441
495
|
return new _ErrorX(options);
|
|
442
496
|
}
|
|
443
|
-
/**
|
|
444
|
-
* Public wrapper for processing error stack traces with delimiter.
|
|
445
|
-
* Delegates to the private processErrorStack method for implementation.
|
|
446
|
-
*
|
|
447
|
-
* @param error - Error whose stack to process
|
|
448
|
-
* @param delimiter - String to search for in stack lines
|
|
449
|
-
* @returns Processed stack trace starting after the delimiter
|
|
450
|
-
*
|
|
451
|
-
* @example
|
|
452
|
-
* ```typescript
|
|
453
|
-
* const error = new Error('Something failed')
|
|
454
|
-
* const cleanStack = ErrorX.processStack(error, 'my-app-entry')
|
|
455
|
-
* // Returns stack trace starting after the line containing 'my-app-entry'
|
|
456
|
-
* ```
|
|
457
|
-
*/
|
|
458
|
-
static processStack(error, delimiter) {
|
|
459
|
-
return _ErrorX.processErrorStack(error, delimiter);
|
|
460
|
-
}
|
|
461
497
|
/**
|
|
462
498
|
* Creates a new ErrorX instance with cleaned stack trace using the specified delimiter.
|
|
463
499
|
* Returns the same instance if no delimiter is provided or no stack is available.
|
|
@@ -481,14 +517,14 @@ var ErrorX = class _ErrorX extends Error {
|
|
|
481
517
|
uiMessage: this.uiMessage,
|
|
482
518
|
cause: this.cause,
|
|
483
519
|
httpStatus: this.httpStatus,
|
|
484
|
-
type: this.type
|
|
520
|
+
type: this.type,
|
|
521
|
+
sourceUrl: this.sourceUrl,
|
|
522
|
+
docsUrl: this.docsUrl,
|
|
523
|
+
source: this.source
|
|
485
524
|
};
|
|
486
525
|
if (this.metadata !== void 0) {
|
|
487
526
|
options.metadata = this.metadata;
|
|
488
527
|
}
|
|
489
|
-
if (this.actions) {
|
|
490
|
-
options.actions = this.actions;
|
|
491
|
-
}
|
|
492
528
|
const newError = new _ErrorX(options);
|
|
493
529
|
newError.stack = _ErrorX.processErrorStack(this, delimiter);
|
|
494
530
|
return newError;
|
|
@@ -551,7 +587,10 @@ ${this.stack}`;
|
|
|
551
587
|
* ```
|
|
552
588
|
*/
|
|
553
589
|
toJSON() {
|
|
554
|
-
|
|
590
|
+
let safeMetadata;
|
|
591
|
+
if (this.metadata) {
|
|
592
|
+
safeMetadata = JSON.parse(safeStringify(this.metadata));
|
|
593
|
+
}
|
|
555
594
|
const serialized = {
|
|
556
595
|
name: this.name,
|
|
557
596
|
message: this.message,
|
|
@@ -560,36 +599,26 @@ ${this.stack}`;
|
|
|
560
599
|
metadata: safeMetadata,
|
|
561
600
|
timestamp: this.timestamp.toISOString()
|
|
562
601
|
};
|
|
563
|
-
if (this.actions && this.actions.length > 0) {
|
|
564
|
-
const stringified = safeStringify(this.actions);
|
|
565
|
-
serialized.actions = JSON.parse(stringified);
|
|
566
|
-
}
|
|
567
602
|
if (this.httpStatus !== void 0) {
|
|
568
603
|
serialized.httpStatus = this.httpStatus;
|
|
569
604
|
}
|
|
570
605
|
if (this.type !== void 0) {
|
|
571
606
|
serialized.type = this.type;
|
|
572
607
|
}
|
|
608
|
+
if (this.sourceUrl !== void 0) {
|
|
609
|
+
serialized.sourceUrl = this.sourceUrl;
|
|
610
|
+
}
|
|
611
|
+
if (this.docsUrl !== void 0) {
|
|
612
|
+
serialized.docsUrl = this.docsUrl;
|
|
613
|
+
}
|
|
614
|
+
if (this.source !== void 0) {
|
|
615
|
+
serialized.source = this.source;
|
|
616
|
+
}
|
|
573
617
|
if (this.stack) {
|
|
574
618
|
serialized.stack = this.stack;
|
|
575
619
|
}
|
|
576
620
|
if (this.cause) {
|
|
577
|
-
|
|
578
|
-
serialized.cause = this.cause.toJSON();
|
|
579
|
-
} else if (this.cause instanceof Error) {
|
|
580
|
-
const causeData = {
|
|
581
|
-
name: this.cause.name,
|
|
582
|
-
message: this.cause.message,
|
|
583
|
-
code: "ERROR",
|
|
584
|
-
uiMessage: void 0,
|
|
585
|
-
metadata: {},
|
|
586
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
587
|
-
};
|
|
588
|
-
if (this.cause.stack) {
|
|
589
|
-
causeData.stack = this.cause.stack;
|
|
590
|
-
}
|
|
591
|
-
serialized.cause = causeData;
|
|
592
|
-
}
|
|
621
|
+
serialized.cause = this.cause;
|
|
593
622
|
}
|
|
594
623
|
return serialized;
|
|
595
624
|
}
|
|
@@ -622,468 +651,342 @@ ${this.stack}`;
|
|
|
622
651
|
code: serialized.code,
|
|
623
652
|
uiMessage: serialized.uiMessage,
|
|
624
653
|
httpStatus: serialized.httpStatus,
|
|
625
|
-
type: serialized.type
|
|
654
|
+
type: serialized.type,
|
|
655
|
+
sourceUrl: serialized.sourceUrl,
|
|
656
|
+
docsUrl: serialized.docsUrl,
|
|
657
|
+
source: serialized.source,
|
|
658
|
+
cause: serialized.cause
|
|
626
659
|
};
|
|
627
660
|
if (serialized.metadata !== void 0) {
|
|
628
661
|
options.metadata = serialized.metadata;
|
|
629
662
|
}
|
|
630
|
-
if (serialized.actions && serialized.actions.length > 0) {
|
|
631
|
-
options.actions = serialized.actions;
|
|
632
|
-
}
|
|
633
663
|
const error = new _ErrorX(options);
|
|
634
664
|
if (serialized.stack) {
|
|
635
665
|
error.stack = serialized.stack;
|
|
636
666
|
}
|
|
637
|
-
|
|
638
|
-
value: new Date(serialized.timestamp),
|
|
639
|
-
writable: false
|
|
640
|
-
});
|
|
641
|
-
if (serialized.cause) {
|
|
642
|
-
Object.defineProperty(error, "cause", {
|
|
643
|
-
value: _ErrorX.fromJSON(serialized.cause),
|
|
644
|
-
writable: false
|
|
645
|
-
});
|
|
646
|
-
}
|
|
667
|
+
error.timestamp = new Date(serialized.timestamp);
|
|
647
668
|
return error;
|
|
648
669
|
}
|
|
649
|
-
/**
|
|
650
|
-
* HTTP error presets for common HTTP status codes.
|
|
651
|
-
*
|
|
652
|
-
* ## Features
|
|
653
|
-
* - **Pre-configured error templates** for common HTTP status codes (400-511)
|
|
654
|
-
* - **Type-safe** with TypeScript support
|
|
655
|
-
* - **Fully customizable** via destructuring and override pattern
|
|
656
|
-
* - **User-friendly messages** included for all presets
|
|
657
|
-
* - **Categorized by type** - all HTTP presets include `type: 'http'`
|
|
658
|
-
*
|
|
659
|
-
* ## Usage Patterns
|
|
660
|
-
*
|
|
661
|
-
* ### 1. Direct Usage
|
|
662
|
-
* Use a preset as-is without any modifications:
|
|
663
|
-
* ```typescript
|
|
664
|
-
* throw new ErrorX(ErrorX.HTTP.NOT_FOUND)
|
|
665
|
-
* // Result: 404 error with default message and UI message
|
|
666
|
-
* ```
|
|
667
|
-
*
|
|
668
|
-
* ### 2. Override Specific Fields
|
|
669
|
-
* Customize the error while keeping other preset values:
|
|
670
|
-
* ```typescript
|
|
671
|
-
* throw new ErrorX({
|
|
672
|
-
* ...ErrorX.HTTP.NOT_FOUND,
|
|
673
|
-
* message: 'User not found',
|
|
674
|
-
* metadata: { userId: 123 }
|
|
675
|
-
* })
|
|
676
|
-
* // Result: 404 error with custom message but keeps httpStatus, code, name, uiMessage, type
|
|
677
|
-
* ```
|
|
678
|
-
*
|
|
679
|
-
* ### 3. Add Metadata and Actions
|
|
680
|
-
* Enhance presets with additional context and behaviors:
|
|
681
|
-
* ```typescript
|
|
682
|
-
* throw new ErrorX({
|
|
683
|
-
* ...ErrorX.HTTP.UNAUTHORIZED,
|
|
684
|
-
* metadata: { attemptedAction: 'viewProfile', userId: 456 },
|
|
685
|
-
* actions: [
|
|
686
|
-
* { action: 'logout', payload: { clearStorage: true } },
|
|
687
|
-
* { action: 'redirect', payload: { redirectURL: '/login' } }
|
|
688
|
-
* ]
|
|
689
|
-
* })
|
|
690
|
-
* ```
|
|
691
|
-
*
|
|
692
|
-
* ### 4. Add Error Cause
|
|
693
|
-
* Chain errors by adding a cause:
|
|
694
|
-
* ```typescript
|
|
695
|
-
* try {
|
|
696
|
-
* // some operation
|
|
697
|
-
* } catch (originalError) {
|
|
698
|
-
* throw new ErrorX({
|
|
699
|
-
* ...ErrorX.HTTP.INTERNAL_SERVER_ERROR,
|
|
700
|
-
* cause: originalError,
|
|
701
|
-
* metadata: { operation: 'database-query' }
|
|
702
|
-
* })
|
|
703
|
-
* }
|
|
704
|
-
* ```
|
|
705
|
-
*
|
|
706
|
-
* ## Common HTTP Presets
|
|
707
|
-
*
|
|
708
|
-
* ### 4xx Client Errors
|
|
709
|
-
* - `BAD_REQUEST` (400) - Invalid request data
|
|
710
|
-
* - `UNAUTHORIZED` (401) - Authentication required
|
|
711
|
-
* - `FORBIDDEN` (403) - Insufficient permissions
|
|
712
|
-
* - `NOT_FOUND` (404) - Resource not found
|
|
713
|
-
* - `METHOD_NOT_ALLOWED` (405) - HTTP method not allowed
|
|
714
|
-
* - `CONFLICT` (409) - Resource conflict
|
|
715
|
-
* - `UNPROCESSABLE_ENTITY` (422) - Validation failed
|
|
716
|
-
* - `TOO_MANY_REQUESTS` (429) - Rate limit exceeded
|
|
717
|
-
*
|
|
718
|
-
* ### 5xx Server Errors
|
|
719
|
-
* - `INTERNAL_SERVER_ERROR` (500) - Unexpected server error
|
|
720
|
-
* - `NOT_IMPLEMENTED` (501) - Feature not implemented
|
|
721
|
-
* - `BAD_GATEWAY` (502) - Upstream server error
|
|
722
|
-
* - `SERVICE_UNAVAILABLE` (503) - Service temporarily down
|
|
723
|
-
* - `GATEWAY_TIMEOUT` (504) - Upstream timeout
|
|
724
|
-
*
|
|
725
|
-
* @example
|
|
726
|
-
* ```typescript
|
|
727
|
-
* // API endpoint example
|
|
728
|
-
* app.get('/users/:id', async (req, res) => {
|
|
729
|
-
* const user = await db.users.findById(req.params.id)
|
|
730
|
-
*
|
|
731
|
-
* if (!user) {
|
|
732
|
-
* throw new ErrorX({
|
|
733
|
-
* ...ErrorX.HTTP.NOT_FOUND,
|
|
734
|
-
* message: 'User not found',
|
|
735
|
-
* metadata: { userId: req.params.id }
|
|
736
|
-
* })
|
|
737
|
-
* }
|
|
738
|
-
*
|
|
739
|
-
* res.json(user)
|
|
740
|
-
* })
|
|
741
|
-
*
|
|
742
|
-
* // Authentication middleware example
|
|
743
|
-
* const requireAuth = (req, res, next) => {
|
|
744
|
-
* if (!req.user) {
|
|
745
|
-
* throw new ErrorX({
|
|
746
|
-
* ...ErrorX.HTTP.UNAUTHORIZED,
|
|
747
|
-
* actions: [
|
|
748
|
-
* { action: 'redirect', payload: { redirectURL: '/login' } }
|
|
749
|
-
* ]
|
|
750
|
-
* })
|
|
751
|
-
* }
|
|
752
|
-
* next()
|
|
753
|
-
* }
|
|
754
|
-
*
|
|
755
|
-
* // Rate limiting example
|
|
756
|
-
* if (isRateLimited(req.ip)) {
|
|
757
|
-
* throw new ErrorX({
|
|
758
|
-
* ...ErrorX.HTTP.TOO_MANY_REQUESTS,
|
|
759
|
-
* metadata: {
|
|
760
|
-
* ip: req.ip,
|
|
761
|
-
* retryAfter: 60
|
|
762
|
-
* }
|
|
763
|
-
* })
|
|
764
|
-
* }
|
|
765
|
-
* ```
|
|
766
|
-
*
|
|
767
|
-
* @public
|
|
768
|
-
*/
|
|
769
|
-
static HTTP = {
|
|
770
|
-
// 4xx Client Errors
|
|
771
|
-
BAD_REQUEST: {
|
|
772
|
-
httpStatus: 400,
|
|
773
|
-
code: "BAD_REQUEST",
|
|
774
|
-
name: "Bad Request Error",
|
|
775
|
-
message: "bad request",
|
|
776
|
-
uiMessage: "The request could not be processed. Please check your input and try again.",
|
|
777
|
-
type: "http"
|
|
778
|
-
},
|
|
779
|
-
UNAUTHORIZED: {
|
|
780
|
-
httpStatus: 401,
|
|
781
|
-
code: "UNAUTHORIZED",
|
|
782
|
-
name: "Unauthorized Error",
|
|
783
|
-
message: "unauthorized",
|
|
784
|
-
uiMessage: "Authentication required. Please log in to continue.",
|
|
785
|
-
type: "http"
|
|
786
|
-
},
|
|
787
|
-
PAYMENT_REQUIRED: {
|
|
788
|
-
httpStatus: 402,
|
|
789
|
-
code: "PAYMENT_REQUIRED",
|
|
790
|
-
name: "Payment Required Error",
|
|
791
|
-
message: "payment required",
|
|
792
|
-
uiMessage: "Payment is required to access this resource.",
|
|
793
|
-
type: "http"
|
|
794
|
-
},
|
|
795
|
-
FORBIDDEN: {
|
|
796
|
-
httpStatus: 403,
|
|
797
|
-
code: "FORBIDDEN",
|
|
798
|
-
name: "Forbidden Error",
|
|
799
|
-
message: "forbidden",
|
|
800
|
-
uiMessage: "You do not have permission to access this resource.",
|
|
801
|
-
type: "http"
|
|
802
|
-
},
|
|
803
|
-
NOT_FOUND: {
|
|
804
|
-
httpStatus: 404,
|
|
805
|
-
code: "NOT_FOUND",
|
|
806
|
-
name: "Not Found Error",
|
|
807
|
-
message: "not found",
|
|
808
|
-
uiMessage: "The requested resource could not be found.",
|
|
809
|
-
type: "http"
|
|
810
|
-
},
|
|
811
|
-
METHOD_NOT_ALLOWED: {
|
|
812
|
-
httpStatus: 405,
|
|
813
|
-
code: "METHOD_NOT_ALLOWED",
|
|
814
|
-
name: "Method Not Allowed Error",
|
|
815
|
-
message: "method not allowed",
|
|
816
|
-
uiMessage: "This action is not allowed for the requested resource.",
|
|
817
|
-
type: "http"
|
|
818
|
-
},
|
|
819
|
-
NOT_ACCEPTABLE: {
|
|
820
|
-
httpStatus: 406,
|
|
821
|
-
code: "NOT_ACCEPTABLE",
|
|
822
|
-
name: "Not Acceptable Error",
|
|
823
|
-
message: "not acceptable",
|
|
824
|
-
uiMessage: "The requested format is not supported.",
|
|
825
|
-
type: "http"
|
|
826
|
-
},
|
|
827
|
-
PROXY_AUTHENTICATION_REQUIRED: {
|
|
828
|
-
httpStatus: 407,
|
|
829
|
-
code: "PROXY_AUTHENTICATION_REQUIRED",
|
|
830
|
-
name: "Proxy Authentication Required Error",
|
|
831
|
-
message: "proxy authentication required",
|
|
832
|
-
uiMessage: "Proxy authentication is required to access this resource.",
|
|
833
|
-
type: "http"
|
|
834
|
-
},
|
|
835
|
-
REQUEST_TIMEOUT: {
|
|
836
|
-
httpStatus: 408,
|
|
837
|
-
code: "REQUEST_TIMEOUT",
|
|
838
|
-
name: "Request Timeout Error",
|
|
839
|
-
message: "request timeout",
|
|
840
|
-
uiMessage: "The request took too long to complete. Please try again.",
|
|
841
|
-
type: "http"
|
|
842
|
-
},
|
|
843
|
-
CONFLICT: {
|
|
844
|
-
httpStatus: 409,
|
|
845
|
-
code: "CONFLICT",
|
|
846
|
-
name: "Conflict Error",
|
|
847
|
-
message: "conflict",
|
|
848
|
-
uiMessage: "The request conflicts with the current state. Please refresh and try again.",
|
|
849
|
-
type: "http"
|
|
850
|
-
},
|
|
851
|
-
GONE: {
|
|
852
|
-
httpStatus: 410,
|
|
853
|
-
code: "GONE",
|
|
854
|
-
name: "Gone Error",
|
|
855
|
-
message: "gone",
|
|
856
|
-
uiMessage: "This resource is no longer available.",
|
|
857
|
-
type: "http"
|
|
858
|
-
},
|
|
859
|
-
LENGTH_REQUIRED: {
|
|
860
|
-
httpStatus: 411,
|
|
861
|
-
code: "LENGTH_REQUIRED",
|
|
862
|
-
name: "Length Required Error",
|
|
863
|
-
message: "length required",
|
|
864
|
-
uiMessage: "The request is missing required length information.",
|
|
865
|
-
type: "http"
|
|
866
|
-
},
|
|
867
|
-
PRECONDITION_FAILED: {
|
|
868
|
-
httpStatus: 412,
|
|
869
|
-
code: "PRECONDITION_FAILED",
|
|
870
|
-
name: "Precondition Failed Error",
|
|
871
|
-
message: "precondition failed",
|
|
872
|
-
uiMessage: "A required condition was not met. Please try again.",
|
|
873
|
-
type: "http"
|
|
874
|
-
},
|
|
875
|
-
PAYLOAD_TOO_LARGE: {
|
|
876
|
-
httpStatus: 413,
|
|
877
|
-
code: "PAYLOAD_TOO_LARGE",
|
|
878
|
-
name: "Payload Too Large Error",
|
|
879
|
-
message: "payload too large",
|
|
880
|
-
uiMessage: "The request is too large. Please reduce the size and try again.",
|
|
881
|
-
type: "http"
|
|
882
|
-
},
|
|
883
|
-
URI_TOO_LONG: {
|
|
884
|
-
httpStatus: 414,
|
|
885
|
-
code: "URI_TOO_LONG",
|
|
886
|
-
name: "URI Too Long Error",
|
|
887
|
-
message: "URI too long",
|
|
888
|
-
uiMessage: "The request URL is too long.",
|
|
889
|
-
type: "http"
|
|
890
|
-
},
|
|
891
|
-
UNSUPPORTED_MEDIA_TYPE: {
|
|
892
|
-
httpStatus: 415,
|
|
893
|
-
code: "UNSUPPORTED_MEDIA_TYPE",
|
|
894
|
-
name: "Unsupported Media Type Error",
|
|
895
|
-
message: "unsupported media type",
|
|
896
|
-
uiMessage: "The file type is not supported.",
|
|
897
|
-
type: "http"
|
|
898
|
-
},
|
|
899
|
-
RANGE_NOT_SATISFIABLE: {
|
|
900
|
-
httpStatus: 416,
|
|
901
|
-
code: "RANGE_NOT_SATISFIABLE",
|
|
902
|
-
name: "Range Not Satisfiable Error",
|
|
903
|
-
message: "range not satisfiable",
|
|
904
|
-
uiMessage: "The requested range cannot be satisfied.",
|
|
905
|
-
type: "http"
|
|
906
|
-
},
|
|
907
|
-
EXPECTATION_FAILED: {
|
|
908
|
-
httpStatus: 417,
|
|
909
|
-
code: "EXPECTATION_FAILED",
|
|
910
|
-
name: "Expectation Failed Error",
|
|
911
|
-
message: "expectation failed",
|
|
912
|
-
uiMessage: "The server cannot meet the requirements of the request.",
|
|
913
|
-
type: "http"
|
|
914
|
-
},
|
|
915
|
-
IM_A_TEAPOT: {
|
|
916
|
-
httpStatus: 418,
|
|
917
|
-
code: "IM_A_TEAPOT",
|
|
918
|
-
name: "Im A Teapot Error",
|
|
919
|
-
message: "i'm a teapot",
|
|
920
|
-
uiMessage: "I'm a teapot and cannot brew coffee.",
|
|
921
|
-
type: "http"
|
|
922
|
-
},
|
|
923
|
-
UNPROCESSABLE_ENTITY: {
|
|
924
|
-
httpStatus: 422,
|
|
925
|
-
code: "UNPROCESSABLE_ENTITY",
|
|
926
|
-
name: "Unprocessable Entity Error",
|
|
927
|
-
message: "unprocessable entity",
|
|
928
|
-
uiMessage: "The request contains invalid data. Please check your input.",
|
|
929
|
-
type: "http"
|
|
930
|
-
},
|
|
931
|
-
LOCKED: {
|
|
932
|
-
httpStatus: 423,
|
|
933
|
-
code: "LOCKED",
|
|
934
|
-
name: "Locked Error",
|
|
935
|
-
message: "locked",
|
|
936
|
-
uiMessage: "This resource is locked and cannot be modified.",
|
|
937
|
-
type: "http"
|
|
938
|
-
},
|
|
939
|
-
FAILED_DEPENDENCY: {
|
|
940
|
-
httpStatus: 424,
|
|
941
|
-
code: "FAILED_DEPENDENCY",
|
|
942
|
-
name: "Failed Dependency Error",
|
|
943
|
-
message: "failed dependency",
|
|
944
|
-
uiMessage: "The request failed due to a dependency error.",
|
|
945
|
-
type: "http"
|
|
946
|
-
},
|
|
947
|
-
TOO_EARLY: {
|
|
948
|
-
httpStatus: 425,
|
|
949
|
-
code: "TOO_EARLY",
|
|
950
|
-
name: "Too Early Error",
|
|
951
|
-
message: "too early",
|
|
952
|
-
uiMessage: "The request was sent too early. Please try again later.",
|
|
953
|
-
type: "http"
|
|
954
|
-
},
|
|
955
|
-
UPGRADE_REQUIRED: {
|
|
956
|
-
httpStatus: 426,
|
|
957
|
-
code: "UPGRADE_REQUIRED",
|
|
958
|
-
name: "Upgrade Required Error",
|
|
959
|
-
message: "upgrade required",
|
|
960
|
-
uiMessage: "Please upgrade to continue using this service.",
|
|
961
|
-
type: "http"
|
|
962
|
-
},
|
|
963
|
-
PRECONDITION_REQUIRED: {
|
|
964
|
-
httpStatus: 428,
|
|
965
|
-
code: "PRECONDITION_REQUIRED",
|
|
966
|
-
name: "Precondition Required Error",
|
|
967
|
-
message: "precondition required",
|
|
968
|
-
uiMessage: "Required conditions are missing from the request.",
|
|
969
|
-
type: "http"
|
|
970
|
-
},
|
|
971
|
-
TOO_MANY_REQUESTS: {
|
|
972
|
-
httpStatus: 429,
|
|
973
|
-
code: "TOO_MANY_REQUESTS",
|
|
974
|
-
name: "Too Many Requests Error",
|
|
975
|
-
message: "too many requests",
|
|
976
|
-
uiMessage: "You have made too many requests. Please wait and try again.",
|
|
977
|
-
type: "http"
|
|
978
|
-
},
|
|
979
|
-
REQUEST_HEADER_FIELDS_TOO_LARGE: {
|
|
980
|
-
httpStatus: 431,
|
|
981
|
-
code: "REQUEST_HEADER_FIELDS_TOO_LARGE",
|
|
982
|
-
name: "Request Header Fields Too Large Error",
|
|
983
|
-
message: "request header fields too large",
|
|
984
|
-
uiMessage: "The request headers are too large.",
|
|
985
|
-
type: "http"
|
|
986
|
-
},
|
|
987
|
-
UNAVAILABLE_FOR_LEGAL_REASONS: {
|
|
988
|
-
httpStatus: 451,
|
|
989
|
-
code: "UNAVAILABLE_FOR_LEGAL_REASONS",
|
|
990
|
-
name: "Unavailable For Legal Reasons Error",
|
|
991
|
-
message: "unavailable for legal reasons",
|
|
992
|
-
uiMessage: "This content is unavailable for legal reasons.",
|
|
993
|
-
type: "http"
|
|
994
|
-
},
|
|
995
|
-
// 5xx Server Errors
|
|
996
|
-
INTERNAL_SERVER_ERROR: {
|
|
997
|
-
httpStatus: 500,
|
|
998
|
-
code: "INTERNAL_SERVER_ERROR",
|
|
999
|
-
name: "Internal Server Error",
|
|
1000
|
-
message: "internal server error",
|
|
1001
|
-
uiMessage: "An unexpected error occurred. Please try again later.",
|
|
1002
|
-
type: "http"
|
|
1003
|
-
},
|
|
1004
|
-
NOT_IMPLEMENTED: {
|
|
1005
|
-
httpStatus: 501,
|
|
1006
|
-
code: "NOT_IMPLEMENTED",
|
|
1007
|
-
name: "Not Implemented Error",
|
|
1008
|
-
message: "not implemented",
|
|
1009
|
-
uiMessage: "This feature is not yet available.",
|
|
1010
|
-
type: "http"
|
|
1011
|
-
},
|
|
1012
|
-
BAD_GATEWAY: {
|
|
1013
|
-
httpStatus: 502,
|
|
1014
|
-
code: "BAD_GATEWAY",
|
|
1015
|
-
name: "Bad Gateway Error",
|
|
1016
|
-
message: "bad gateway",
|
|
1017
|
-
uiMessage: "Unable to connect to the server. Please try again later.",
|
|
1018
|
-
type: "http"
|
|
1019
|
-
},
|
|
1020
|
-
SERVICE_UNAVAILABLE: {
|
|
1021
|
-
httpStatus: 503,
|
|
1022
|
-
code: "SERVICE_UNAVAILABLE",
|
|
1023
|
-
name: "Service Unavailable Error",
|
|
1024
|
-
message: "service unavailable",
|
|
1025
|
-
uiMessage: "The service is temporarily unavailable. Please try again later.",
|
|
1026
|
-
type: "http"
|
|
1027
|
-
},
|
|
1028
|
-
GATEWAY_TIMEOUT: {
|
|
1029
|
-
httpStatus: 504,
|
|
1030
|
-
code: "GATEWAY_TIMEOUT",
|
|
1031
|
-
name: "Gateway Timeout Error",
|
|
1032
|
-
message: "gateway timeout",
|
|
1033
|
-
uiMessage: "The server took too long to respond. Please try again.",
|
|
1034
|
-
type: "http"
|
|
1035
|
-
},
|
|
1036
|
-
HTTP_VERSION_NOT_SUPPORTED: {
|
|
1037
|
-
httpStatus: 505,
|
|
1038
|
-
code: "HTTP_VERSION_NOT_SUPPORTED",
|
|
1039
|
-
name: "HTTP Version Not Supported Error",
|
|
1040
|
-
message: "HTTP version not supported",
|
|
1041
|
-
uiMessage: "Your browser version is not supported.",
|
|
1042
|
-
type: "http"
|
|
1043
|
-
},
|
|
1044
|
-
VARIANT_ALSO_NEGOTIATES: {
|
|
1045
|
-
httpStatus: 506,
|
|
1046
|
-
code: "VARIANT_ALSO_NEGOTIATES",
|
|
1047
|
-
name: "Variant Also Negotiates Error",
|
|
1048
|
-
message: "variant also negotiates",
|
|
1049
|
-
uiMessage: "The server has an internal configuration error.",
|
|
1050
|
-
type: "http"
|
|
1051
|
-
},
|
|
1052
|
-
INSUFFICIENT_STORAGE: {
|
|
1053
|
-
httpStatus: 507,
|
|
1054
|
-
code: "INSUFFICIENT_STORAGE",
|
|
1055
|
-
name: "Insufficient Storage Error",
|
|
1056
|
-
message: "insufficient storage",
|
|
1057
|
-
uiMessage: "The server has insufficient storage to complete the request.",
|
|
1058
|
-
type: "http"
|
|
1059
|
-
},
|
|
1060
|
-
LOOP_DETECTED: {
|
|
1061
|
-
httpStatus: 508,
|
|
1062
|
-
code: "LOOP_DETECTED",
|
|
1063
|
-
name: "Loop Detected Error",
|
|
1064
|
-
message: "loop detected",
|
|
1065
|
-
uiMessage: "The server detected an infinite loop.",
|
|
1066
|
-
type: "http"
|
|
1067
|
-
},
|
|
1068
|
-
NOT_EXTENDED: {
|
|
1069
|
-
httpStatus: 510,
|
|
1070
|
-
code: "NOT_EXTENDED",
|
|
1071
|
-
name: "Not Extended Error",
|
|
1072
|
-
message: "not extended",
|
|
1073
|
-
uiMessage: "Additional extensions are required.",
|
|
1074
|
-
type: "http"
|
|
1075
|
-
},
|
|
1076
|
-
NETWORK_AUTHENTICATION_REQUIRED: {
|
|
1077
|
-
httpStatus: 511,
|
|
1078
|
-
code: "NETWORK_AUTHENTICATION_REQUIRED",
|
|
1079
|
-
name: "Network Authentication Required Error",
|
|
1080
|
-
message: "network authentication required",
|
|
1081
|
-
uiMessage: "Network authentication is required to access this resource.",
|
|
1082
|
-
type: "http"
|
|
1083
|
-
}
|
|
1084
|
-
};
|
|
1085
670
|
};
|
|
1086
671
|
|
|
1087
|
-
|
|
672
|
+
// src/presets.ts
|
|
673
|
+
var http = {
|
|
674
|
+
// 4xx Client Errors
|
|
675
|
+
badRequest: {
|
|
676
|
+
httpStatus: 400,
|
|
677
|
+
code: "BAD_REQUEST",
|
|
678
|
+
name: "Bad Request Error",
|
|
679
|
+
message: "Bad request.",
|
|
680
|
+
uiMessage: "The request could not be processed. Please check your input and try again.",
|
|
681
|
+
type: "http"
|
|
682
|
+
},
|
|
683
|
+
unauthorized: {
|
|
684
|
+
httpStatus: 401,
|
|
685
|
+
code: "UNAUTHORIZED",
|
|
686
|
+
name: "Unauthorized Error",
|
|
687
|
+
message: "Unauthorized.",
|
|
688
|
+
uiMessage: "Authentication required. Please log in to continue.",
|
|
689
|
+
type: "http"
|
|
690
|
+
},
|
|
691
|
+
paymentRequired: {
|
|
692
|
+
httpStatus: 402,
|
|
693
|
+
code: "PAYMENT_REQUIRED",
|
|
694
|
+
name: "Payment Required Error",
|
|
695
|
+
message: "Payment required.",
|
|
696
|
+
uiMessage: "Payment is required to access this resource.",
|
|
697
|
+
type: "http"
|
|
698
|
+
},
|
|
699
|
+
forbidden: {
|
|
700
|
+
httpStatus: 403,
|
|
701
|
+
code: "FORBIDDEN",
|
|
702
|
+
name: "Forbidden Error",
|
|
703
|
+
message: "Forbidden.",
|
|
704
|
+
uiMessage: "You do not have permission to access this resource.",
|
|
705
|
+
type: "http"
|
|
706
|
+
},
|
|
707
|
+
notFound: {
|
|
708
|
+
httpStatus: 404,
|
|
709
|
+
code: "NOT_FOUND",
|
|
710
|
+
name: "Not Found Error",
|
|
711
|
+
message: "Not found.",
|
|
712
|
+
uiMessage: "The requested resource could not be found.",
|
|
713
|
+
type: "http"
|
|
714
|
+
},
|
|
715
|
+
methodNotAllowed: {
|
|
716
|
+
httpStatus: 405,
|
|
717
|
+
code: "METHOD_NOT_ALLOWED",
|
|
718
|
+
name: "Method Not Allowed Error",
|
|
719
|
+
message: "Method not allowed.",
|
|
720
|
+
uiMessage: "This action is not allowed for the requested resource.",
|
|
721
|
+
type: "http"
|
|
722
|
+
},
|
|
723
|
+
notAcceptable: {
|
|
724
|
+
httpStatus: 406,
|
|
725
|
+
code: "NOT_ACCEPTABLE",
|
|
726
|
+
name: "Not Acceptable Error",
|
|
727
|
+
message: "Not acceptable.",
|
|
728
|
+
uiMessage: "The requested format is not supported.",
|
|
729
|
+
type: "http"
|
|
730
|
+
},
|
|
731
|
+
proxyAuthenticationRequired: {
|
|
732
|
+
httpStatus: 407,
|
|
733
|
+
code: "PROXY_AUTHENTICATION_REQUIRED",
|
|
734
|
+
name: "Proxy Authentication Required Error",
|
|
735
|
+
message: "Proxy authentication required.",
|
|
736
|
+
uiMessage: "Proxy authentication is required to access this resource.",
|
|
737
|
+
type: "http"
|
|
738
|
+
},
|
|
739
|
+
requestTimeout: {
|
|
740
|
+
httpStatus: 408,
|
|
741
|
+
code: "REQUEST_TIMEOUT",
|
|
742
|
+
name: "Request Timeout Error",
|
|
743
|
+
message: "Request timeout.",
|
|
744
|
+
uiMessage: "The request took too long to complete. Please try again.",
|
|
745
|
+
type: "http"
|
|
746
|
+
},
|
|
747
|
+
conflict: {
|
|
748
|
+
httpStatus: 409,
|
|
749
|
+
code: "CONFLICT",
|
|
750
|
+
name: "Conflict Error",
|
|
751
|
+
message: "Conflict.",
|
|
752
|
+
uiMessage: "The request conflicts with the current state. Please refresh and try again.",
|
|
753
|
+
type: "http"
|
|
754
|
+
},
|
|
755
|
+
gone: {
|
|
756
|
+
httpStatus: 410,
|
|
757
|
+
code: "GONE",
|
|
758
|
+
name: "Gone Error",
|
|
759
|
+
message: "Gone.",
|
|
760
|
+
uiMessage: "This resource is no longer available.",
|
|
761
|
+
type: "http"
|
|
762
|
+
},
|
|
763
|
+
lengthRequired: {
|
|
764
|
+
httpStatus: 411,
|
|
765
|
+
code: "LENGTH_REQUIRED",
|
|
766
|
+
name: "Length Required Error",
|
|
767
|
+
message: "Length required.",
|
|
768
|
+
uiMessage: "The request is missing required length information.",
|
|
769
|
+
type: "http"
|
|
770
|
+
},
|
|
771
|
+
preconditionFailed: {
|
|
772
|
+
httpStatus: 412,
|
|
773
|
+
code: "PRECONDITION_FAILED",
|
|
774
|
+
name: "Precondition Failed Error",
|
|
775
|
+
message: "Precondition failed.",
|
|
776
|
+
uiMessage: "A required condition was not met. Please try again.",
|
|
777
|
+
type: "http"
|
|
778
|
+
},
|
|
779
|
+
payloadTooLarge: {
|
|
780
|
+
httpStatus: 413,
|
|
781
|
+
code: "PAYLOAD_TOO_LARGE",
|
|
782
|
+
name: "Payload Too Large Error",
|
|
783
|
+
message: "Payload too large.",
|
|
784
|
+
uiMessage: "The request is too large. Please reduce the size and try again.",
|
|
785
|
+
type: "http"
|
|
786
|
+
},
|
|
787
|
+
uriTooLong: {
|
|
788
|
+
httpStatus: 414,
|
|
789
|
+
code: "URI_TOO_LONG",
|
|
790
|
+
name: "URI Too Long Error",
|
|
791
|
+
message: "URI too long.",
|
|
792
|
+
uiMessage: "The request URL is too long.",
|
|
793
|
+
type: "http"
|
|
794
|
+
},
|
|
795
|
+
unsupportedMediaType: {
|
|
796
|
+
httpStatus: 415,
|
|
797
|
+
code: "UNSUPPORTED_MEDIA_TYPE",
|
|
798
|
+
name: "Unsupported Media Type Error",
|
|
799
|
+
message: "Unsupported media type.",
|
|
800
|
+
uiMessage: "The file type is not supported.",
|
|
801
|
+
type: "http"
|
|
802
|
+
},
|
|
803
|
+
rangeNotSatisfiable: {
|
|
804
|
+
httpStatus: 416,
|
|
805
|
+
code: "RANGE_NOT_SATISFIABLE",
|
|
806
|
+
name: "Range Not Satisfiable Error",
|
|
807
|
+
message: "Range not satisfiable.",
|
|
808
|
+
uiMessage: "The requested range cannot be satisfied.",
|
|
809
|
+
type: "http"
|
|
810
|
+
},
|
|
811
|
+
expectationFailed: {
|
|
812
|
+
httpStatus: 417,
|
|
813
|
+
code: "EXPECTATION_FAILED",
|
|
814
|
+
name: "Expectation Failed Error",
|
|
815
|
+
message: "Expectation failed.",
|
|
816
|
+
uiMessage: "The server cannot meet the requirements of the request.",
|
|
817
|
+
type: "http"
|
|
818
|
+
},
|
|
819
|
+
imATeapot: {
|
|
820
|
+
httpStatus: 418,
|
|
821
|
+
code: "IM_A_TEAPOT",
|
|
822
|
+
name: "Im A Teapot Error",
|
|
823
|
+
message: "I'm a teapot.",
|
|
824
|
+
uiMessage: "I'm a teapot and cannot brew coffee.",
|
|
825
|
+
type: "http"
|
|
826
|
+
},
|
|
827
|
+
unprocessableEntity: {
|
|
828
|
+
httpStatus: 422,
|
|
829
|
+
code: "UNPROCESSABLE_ENTITY",
|
|
830
|
+
name: "Unprocessable Entity Error",
|
|
831
|
+
message: "Unprocessable entity.",
|
|
832
|
+
uiMessage: "The request contains invalid data. Please check your input.",
|
|
833
|
+
type: "http"
|
|
834
|
+
},
|
|
835
|
+
locked: {
|
|
836
|
+
httpStatus: 423,
|
|
837
|
+
code: "LOCKED",
|
|
838
|
+
name: "Locked Error",
|
|
839
|
+
message: "Locked.",
|
|
840
|
+
uiMessage: "This resource is locked and cannot be modified.",
|
|
841
|
+
type: "http"
|
|
842
|
+
},
|
|
843
|
+
failedDependency: {
|
|
844
|
+
httpStatus: 424,
|
|
845
|
+
code: "FAILED_DEPENDENCY",
|
|
846
|
+
name: "Failed Dependency Error",
|
|
847
|
+
message: "Failed dependency.",
|
|
848
|
+
uiMessage: "The request failed due to a dependency error.",
|
|
849
|
+
type: "http"
|
|
850
|
+
},
|
|
851
|
+
tooEarly: {
|
|
852
|
+
httpStatus: 425,
|
|
853
|
+
code: "TOO_EARLY",
|
|
854
|
+
name: "Too Early Error",
|
|
855
|
+
message: "Too early.",
|
|
856
|
+
uiMessage: "The request was sent too early. Please try again later.",
|
|
857
|
+
type: "http"
|
|
858
|
+
},
|
|
859
|
+
upgradeRequired: {
|
|
860
|
+
httpStatus: 426,
|
|
861
|
+
code: "UPGRADE_REQUIRED",
|
|
862
|
+
name: "Upgrade Required Error",
|
|
863
|
+
message: "Upgrade required.",
|
|
864
|
+
uiMessage: "Please upgrade to continue using this service.",
|
|
865
|
+
type: "http"
|
|
866
|
+
},
|
|
867
|
+
preconditionRequired: {
|
|
868
|
+
httpStatus: 428,
|
|
869
|
+
code: "PRECONDITION_REQUIRED",
|
|
870
|
+
name: "Precondition Required Error",
|
|
871
|
+
message: "Precondition required.",
|
|
872
|
+
uiMessage: "Required conditions are missing from the request.",
|
|
873
|
+
type: "http"
|
|
874
|
+
},
|
|
875
|
+
tooManyRequests: {
|
|
876
|
+
httpStatus: 429,
|
|
877
|
+
code: "TOO_MANY_REQUESTS",
|
|
878
|
+
name: "Too Many Requests Error",
|
|
879
|
+
message: "Too many requests.",
|
|
880
|
+
uiMessage: "You have made too many requests. Please wait and try again.",
|
|
881
|
+
type: "http"
|
|
882
|
+
},
|
|
883
|
+
requestHeaderFieldsTooLarge: {
|
|
884
|
+
httpStatus: 431,
|
|
885
|
+
code: "REQUEST_HEADER_FIELDS_TOO_LARGE",
|
|
886
|
+
name: "Request Header Fields Too Large Error",
|
|
887
|
+
message: "Request header fields too large.",
|
|
888
|
+
uiMessage: "The request headers are too large.",
|
|
889
|
+
type: "http"
|
|
890
|
+
},
|
|
891
|
+
unavailableForLegalReasons: {
|
|
892
|
+
httpStatus: 451,
|
|
893
|
+
code: "UNAVAILABLE_FOR_LEGAL_REASONS",
|
|
894
|
+
name: "Unavailable For Legal Reasons Error",
|
|
895
|
+
message: "Unavailable for legal reasons.",
|
|
896
|
+
uiMessage: "This content is unavailable for legal reasons.",
|
|
897
|
+
type: "http"
|
|
898
|
+
},
|
|
899
|
+
// 5xx Server Errors
|
|
900
|
+
internalServerError: {
|
|
901
|
+
httpStatus: 500,
|
|
902
|
+
code: "INTERNAL_SERVER_ERROR",
|
|
903
|
+
name: "Internal Server Error",
|
|
904
|
+
message: "Internal server error.",
|
|
905
|
+
uiMessage: "An unexpected error occurred. Please try again later.",
|
|
906
|
+
type: "http"
|
|
907
|
+
},
|
|
908
|
+
notImplemented: {
|
|
909
|
+
httpStatus: 501,
|
|
910
|
+
code: "NOT_IMPLEMENTED",
|
|
911
|
+
name: "Not Implemented Error",
|
|
912
|
+
message: "Not implemented.",
|
|
913
|
+
uiMessage: "This feature is not yet available.",
|
|
914
|
+
type: "http"
|
|
915
|
+
},
|
|
916
|
+
badGateway: {
|
|
917
|
+
httpStatus: 502,
|
|
918
|
+
code: "BAD_GATEWAY",
|
|
919
|
+
name: "Bad Gateway Error",
|
|
920
|
+
message: "Bad gateway.",
|
|
921
|
+
uiMessage: "Unable to connect to the server. Please try again later.",
|
|
922
|
+
type: "http"
|
|
923
|
+
},
|
|
924
|
+
serviceUnavailable: {
|
|
925
|
+
httpStatus: 503,
|
|
926
|
+
code: "SERVICE_UNAVAILABLE",
|
|
927
|
+
name: "Service Unavailable Error",
|
|
928
|
+
message: "Service unavailable.",
|
|
929
|
+
uiMessage: "The service is temporarily unavailable. Please try again later.",
|
|
930
|
+
type: "http"
|
|
931
|
+
},
|
|
932
|
+
gatewayTimeout: {
|
|
933
|
+
httpStatus: 504,
|
|
934
|
+
code: "GATEWAY_TIMEOUT",
|
|
935
|
+
name: "Gateway Timeout Error",
|
|
936
|
+
message: "Gateway timeout.",
|
|
937
|
+
uiMessage: "The server took too long to respond. Please try again.",
|
|
938
|
+
type: "http"
|
|
939
|
+
},
|
|
940
|
+
httpVersionNotSupported: {
|
|
941
|
+
httpStatus: 505,
|
|
942
|
+
code: "HTTP_VERSION_NOT_SUPPORTED",
|
|
943
|
+
name: "HTTP Version Not Supported Error",
|
|
944
|
+
message: "HTTP version not supported.",
|
|
945
|
+
uiMessage: "Your browser version is not supported.",
|
|
946
|
+
type: "http"
|
|
947
|
+
},
|
|
948
|
+
variantAlsoNegotiates: {
|
|
949
|
+
httpStatus: 506,
|
|
950
|
+
code: "VARIANT_ALSO_NEGOTIATES",
|
|
951
|
+
name: "Variant Also Negotiates Error",
|
|
952
|
+
message: "Variant also negotiates.",
|
|
953
|
+
uiMessage: "The server has an internal configuration error.",
|
|
954
|
+
type: "http"
|
|
955
|
+
},
|
|
956
|
+
insufficientStorage: {
|
|
957
|
+
httpStatus: 507,
|
|
958
|
+
code: "INSUFFICIENT_STORAGE",
|
|
959
|
+
name: "Insufficient Storage Error",
|
|
960
|
+
message: "Insufficient storage.",
|
|
961
|
+
uiMessage: "The server has insufficient storage to complete the request.",
|
|
962
|
+
type: "http"
|
|
963
|
+
},
|
|
964
|
+
loopDetected: {
|
|
965
|
+
httpStatus: 508,
|
|
966
|
+
code: "LOOP_DETECTED",
|
|
967
|
+
name: "Loop Detected Error",
|
|
968
|
+
message: "Loop detected.",
|
|
969
|
+
uiMessage: "The server detected an infinite loop.",
|
|
970
|
+
type: "http"
|
|
971
|
+
},
|
|
972
|
+
notExtended: {
|
|
973
|
+
httpStatus: 510,
|
|
974
|
+
code: "NOT_EXTENDED",
|
|
975
|
+
name: "Not Extended Error",
|
|
976
|
+
message: "Not extended.",
|
|
977
|
+
uiMessage: "Additional extensions are required.",
|
|
978
|
+
type: "http"
|
|
979
|
+
},
|
|
980
|
+
networkAuthenticationRequired: {
|
|
981
|
+
httpStatus: 511,
|
|
982
|
+
code: "NETWORK_AUTHENTICATION_REQUIRED",
|
|
983
|
+
name: "Network Authentication Required Error",
|
|
984
|
+
message: "Network authentication required.",
|
|
985
|
+
uiMessage: "Network authentication is required to access this resource.",
|
|
986
|
+
type: "http"
|
|
987
|
+
}
|
|
988
|
+
};
|
|
989
|
+
|
|
990
|
+
export { ErrorX, http };
|
|
1088
991
|
//# sourceMappingURL=index.js.map
|
|
1089
992
|
//# sourceMappingURL=index.js.map
|