@naturalcycles/js-lib 14.173.0 → 14.174.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/dist/error/error.util.d.ts +23 -13
- package/dist/error/error.util.js +10 -1
- package/dist-esm/error/error.util.js +10 -1
- package/package.json +1 -1
- package/src/error/error.util.ts +34 -17
|
@@ -55,6 +55,26 @@ export declare function _isErrorLike(o: any): o is ErrorLike;
|
|
|
55
55
|
* }
|
|
56
56
|
*/
|
|
57
57
|
export declare function _errorDataAppend<ERR>(err: ERR, data?: ErrorData): ERR;
|
|
58
|
+
export interface AppErrorComponents<DATA_TYPE extends ErrorData = ErrorData> {
|
|
59
|
+
message: string;
|
|
60
|
+
name?: string;
|
|
61
|
+
data?: DATA_TYPE;
|
|
62
|
+
cause?: any;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Extra options for AppError constructor.
|
|
66
|
+
*/
|
|
67
|
+
export interface AppErrorOptions {
|
|
68
|
+
/**
|
|
69
|
+
* Overrides Error.name and Error.constructor.name
|
|
70
|
+
*/
|
|
71
|
+
name?: string;
|
|
72
|
+
/**
|
|
73
|
+
* Sets Error.cause.
|
|
74
|
+
* It is transformed with _anyToErrorObject()
|
|
75
|
+
*/
|
|
76
|
+
cause?: any;
|
|
77
|
+
}
|
|
58
78
|
/**
|
|
59
79
|
* Base class for all our (not system) errors.
|
|
60
80
|
*
|
|
@@ -70,21 +90,11 @@ export declare class AppError<DATA_TYPE extends ErrorData = ErrorData> extends E
|
|
|
70
90
|
* `cause` here is normalized to be an ErrorObject
|
|
71
91
|
*/
|
|
72
92
|
cause?: ErrorObject;
|
|
73
|
-
constructor(message: string, data?: DATA_TYPE, opt?: AppErrorOptions);
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Extra options for AppError constructor.
|
|
77
|
-
*/
|
|
78
|
-
export interface AppErrorOptions {
|
|
79
93
|
/**
|
|
80
|
-
*
|
|
94
|
+
* Experimental alternative static constructor.
|
|
81
95
|
*/
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
* Sets Error.cause.
|
|
85
|
-
* It is transformed with _anyToErrorObject()
|
|
86
|
-
*/
|
|
87
|
-
cause?: any;
|
|
96
|
+
static of<DATA_TYPE extends ErrorData = ErrorData>(opt: AppErrorComponents): AppError<DATA_TYPE>;
|
|
97
|
+
constructor(message: string, data?: DATA_TYPE, opt?: AppErrorOptions);
|
|
88
98
|
}
|
|
89
99
|
/**
|
|
90
100
|
* Error that is thrown when Http Request was made and returned an error.
|
package/dist/error/error.util.js
CHANGED
|
@@ -235,9 +235,18 @@ exports._errorDataAppend = _errorDataAppend;
|
|
|
235
235
|
* Based on: https://medium.com/@xpl/javascript-deriving-from-error-properly-8d2f8f315801
|
|
236
236
|
*/
|
|
237
237
|
class AppError extends Error {
|
|
238
|
+
/**
|
|
239
|
+
* Experimental alternative static constructor.
|
|
240
|
+
*/
|
|
241
|
+
static of(opt) {
|
|
242
|
+
return new AppError(opt.message, opt.data, {
|
|
243
|
+
name: opt.name,
|
|
244
|
+
cause: opt.cause,
|
|
245
|
+
});
|
|
246
|
+
}
|
|
238
247
|
constructor(message, data = {}, opt = {}) {
|
|
239
248
|
super(message);
|
|
240
|
-
const { name =
|
|
249
|
+
const { name = 'AppError', cause } = opt;
|
|
241
250
|
Object.defineProperties(this, {
|
|
242
251
|
name: {
|
|
243
252
|
value: name,
|
|
@@ -217,9 +217,18 @@ export function _errorDataAppend(err, data) {
|
|
|
217
217
|
* Based on: https://medium.com/@xpl/javascript-deriving-from-error-properly-8d2f8f315801
|
|
218
218
|
*/
|
|
219
219
|
export class AppError extends Error {
|
|
220
|
+
/**
|
|
221
|
+
* Experimental alternative static constructor.
|
|
222
|
+
*/
|
|
223
|
+
static of(opt) {
|
|
224
|
+
return new AppError(opt.message, opt.data, {
|
|
225
|
+
name: opt.name,
|
|
226
|
+
cause: opt.cause,
|
|
227
|
+
});
|
|
228
|
+
}
|
|
220
229
|
constructor(message, data = {}, opt = {}) {
|
|
221
230
|
super(message);
|
|
222
|
-
const { name =
|
|
231
|
+
const { name = 'AppError', cause } = opt;
|
|
223
232
|
Object.defineProperties(this, {
|
|
224
233
|
name: {
|
|
225
234
|
value: name,
|
package/package.json
CHANGED
package/src/error/error.util.ts
CHANGED
|
@@ -273,6 +273,29 @@ export function _errorDataAppend<ERR>(err: ERR, data?: ErrorData): ERR {
|
|
|
273
273
|
return err
|
|
274
274
|
}
|
|
275
275
|
|
|
276
|
+
export interface AppErrorComponents<DATA_TYPE extends ErrorData = ErrorData> {
|
|
277
|
+
message: string
|
|
278
|
+
name?: string
|
|
279
|
+
data?: DATA_TYPE
|
|
280
|
+
cause?: any
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Extra options for AppError constructor.
|
|
285
|
+
*/
|
|
286
|
+
export interface AppErrorOptions {
|
|
287
|
+
/**
|
|
288
|
+
* Overrides Error.name and Error.constructor.name
|
|
289
|
+
*/
|
|
290
|
+
name?: string
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Sets Error.cause.
|
|
294
|
+
* It is transformed with _anyToErrorObject()
|
|
295
|
+
*/
|
|
296
|
+
cause?: any
|
|
297
|
+
}
|
|
298
|
+
|
|
276
299
|
/**
|
|
277
300
|
* Base class for all our (not system) errors.
|
|
278
301
|
*
|
|
@@ -290,9 +313,19 @@ export class AppError<DATA_TYPE extends ErrorData = ErrorData> extends Error {
|
|
|
290
313
|
*/
|
|
291
314
|
override cause?: ErrorObject
|
|
292
315
|
|
|
316
|
+
/**
|
|
317
|
+
* Experimental alternative static constructor.
|
|
318
|
+
*/
|
|
319
|
+
static of<DATA_TYPE extends ErrorData = ErrorData>(opt: AppErrorComponents): AppError<DATA_TYPE> {
|
|
320
|
+
return new AppError<DATA_TYPE>(opt.message, opt.data as DATA_TYPE, {
|
|
321
|
+
name: opt.name,
|
|
322
|
+
cause: opt.cause,
|
|
323
|
+
})
|
|
324
|
+
}
|
|
325
|
+
|
|
293
326
|
constructor(message: string, data = {} as DATA_TYPE, opt: AppErrorOptions = {}) {
|
|
294
327
|
super(message)
|
|
295
|
-
const { name =
|
|
328
|
+
const { name = 'AppError', cause } = opt
|
|
296
329
|
|
|
297
330
|
Object.defineProperties(this, {
|
|
298
331
|
name: {
|
|
@@ -337,22 +370,6 @@ export class AppError<DATA_TYPE extends ErrorData = ErrorData> extends Error {
|
|
|
337
370
|
}
|
|
338
371
|
}
|
|
339
372
|
|
|
340
|
-
/**
|
|
341
|
-
* Extra options for AppError constructor.
|
|
342
|
-
*/
|
|
343
|
-
export interface AppErrorOptions {
|
|
344
|
-
/**
|
|
345
|
-
* Overrides Error.name and Error.constructor.name
|
|
346
|
-
*/
|
|
347
|
-
name?: string
|
|
348
|
-
|
|
349
|
-
/**
|
|
350
|
-
* Sets Error.cause.
|
|
351
|
-
* It is transformed with _anyToErrorObject()
|
|
352
|
-
*/
|
|
353
|
-
cause?: any
|
|
354
|
-
}
|
|
355
|
-
|
|
356
373
|
/**
|
|
357
374
|
* Error that is thrown when Http Request was made and returned an error.
|
|
358
375
|
* Thrown by, for example, Fetcher.
|