@naturalcycles/js-lib 14.130.0 → 14.130.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/dist/error/app.error.d.ts +4 -0
- package/dist/error/app.error.js +10 -1
- package/dist/error/error.model.d.ts +1 -1
- package/dist/error/error.util.d.ts +0 -1
- package/dist/error/error.util.js +1 -5
- package/dist-esm/error/app.error.js +10 -1
- package/dist-esm/error/error.util.js +1 -4
- package/package.json +1 -1
- package/src/error/app.error.ts +16 -1
- package/src/error/error.model.ts +1 -1
- package/src/error/error.util.ts +1 -7
|
@@ -10,5 +10,9 @@ import type { ErrorData } from './error.model';
|
|
|
10
10
|
*/
|
|
11
11
|
export declare class AppError<DATA_TYPE extends ErrorData = ErrorData> extends Error {
|
|
12
12
|
data: DATA_TYPE;
|
|
13
|
+
/**
|
|
14
|
+
* cause here is normalized to be instance of Error
|
|
15
|
+
*/
|
|
16
|
+
cause?: Error;
|
|
13
17
|
constructor(message: string, data?: DATA_TYPE, opt?: ErrorOptions);
|
|
14
18
|
}
|
package/dist/error/app.error.js
CHANGED
|
@@ -12,7 +12,7 @@ exports.AppError = void 0;
|
|
|
12
12
|
*/
|
|
13
13
|
class AppError extends Error {
|
|
14
14
|
constructor(message, data = {}, opt) {
|
|
15
|
-
super(message
|
|
15
|
+
super(message);
|
|
16
16
|
Object.defineProperty(this, 'name', {
|
|
17
17
|
value: this.constructor.name,
|
|
18
18
|
configurable: true,
|
|
@@ -23,6 +23,15 @@ class AppError extends Error {
|
|
|
23
23
|
configurable: true,
|
|
24
24
|
enumerable: false,
|
|
25
25
|
});
|
|
26
|
+
if (opt?.cause) {
|
|
27
|
+
Object.defineProperty(this, 'cause', {
|
|
28
|
+
// I'd love to do _anyToError(opt.cause) here, but it causes circular dep ;(
|
|
29
|
+
value: opt.cause,
|
|
30
|
+
writable: true,
|
|
31
|
+
configurable: true,
|
|
32
|
+
enumerable: false,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
26
35
|
// todo: check if it's needed at all!
|
|
27
36
|
// if (Error.captureStackTrace) {
|
|
28
37
|
// Error.captureStackTrace(this, this.constructor)
|
|
@@ -93,7 +93,7 @@ export interface ErrorObject<DATA_TYPE extends ErrorData = ErrorData> {
|
|
|
93
93
|
* It's non-optional, to save some null-checks.
|
|
94
94
|
*/
|
|
95
95
|
data: DATA_TYPE;
|
|
96
|
-
cause?:
|
|
96
|
+
cause?: ErrorObject;
|
|
97
97
|
}
|
|
98
98
|
/**
|
|
99
99
|
* JSON HTTP response from the Backend that represents "Error".
|
|
@@ -17,7 +17,6 @@ export declare function _anyToError<ERROR_TYPE extends Error = Error>(o: any, er
|
|
|
17
17
|
*/
|
|
18
18
|
export declare function _anyToErrorObject<DATA_TYPE extends ErrorData = ErrorData>(o: any, errorData?: Partial<DATA_TYPE>): ErrorObject<DATA_TYPE>;
|
|
19
19
|
export declare function _errorToErrorObject<DATA_TYPE extends ErrorData = ErrorData>(e: AppError<DATA_TYPE> | Error): ErrorObject<DATA_TYPE>;
|
|
20
|
-
export declare function _errorObjectToAppError<DATA_TYPE extends ErrorData>(o: ErrorObject<DATA_TYPE>): AppError<DATA_TYPE>;
|
|
21
20
|
export declare function _errorObjectToError<DATA_TYPE extends ErrorData, ERROR_TYPE extends Error>(o: ErrorObject<DATA_TYPE>, errorClass?: Class<ERROR_TYPE>): ERROR_TYPE;
|
|
22
21
|
export declare function _isHttpErrorResponse(o: any): o is HttpErrorResponse;
|
|
23
22
|
export declare function _isHttpErrorObject(o: any): o is ErrorObject<HttpErrorData>;
|
package/dist/error/error.util.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports._errorDataAppend = exports._isErrorObject = exports._isHttpErrorObject = exports._isHttpErrorResponse = exports._errorObjectToError = exports.
|
|
3
|
+
exports._errorDataAppend = exports._isErrorObject = exports._isHttpErrorObject = exports._isHttpErrorResponse = exports._errorObjectToError = exports._errorToErrorObject = exports._anyToErrorObject = exports._anyToError = void 0;
|
|
4
4
|
const __1 = require("..");
|
|
5
5
|
/**
|
|
6
6
|
* Useful to ensure that error in `catch (err) { ... }`
|
|
@@ -79,10 +79,6 @@ function _errorToErrorObject(e) {
|
|
|
79
79
|
return obj;
|
|
80
80
|
}
|
|
81
81
|
exports._errorToErrorObject = _errorToErrorObject;
|
|
82
|
-
function _errorObjectToAppError(o) {
|
|
83
|
-
return _errorObjectToError(o, __1.AppError);
|
|
84
|
-
}
|
|
85
|
-
exports._errorObjectToAppError = _errorObjectToAppError;
|
|
86
82
|
function _errorObjectToError(o, errorClass = Error) {
|
|
87
83
|
if (o instanceof errorClass)
|
|
88
84
|
return o;
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
export class AppError extends Error {
|
|
11
11
|
constructor(message, data = {}, opt) {
|
|
12
|
-
super(message
|
|
12
|
+
super(message);
|
|
13
13
|
Object.defineProperty(this, 'name', {
|
|
14
14
|
value: this.constructor.name,
|
|
15
15
|
configurable: true,
|
|
@@ -20,6 +20,15 @@ export class AppError extends Error {
|
|
|
20
20
|
configurable: true,
|
|
21
21
|
enumerable: false,
|
|
22
22
|
});
|
|
23
|
+
if (opt === null || opt === void 0 ? void 0 : opt.cause) {
|
|
24
|
+
Object.defineProperty(this, 'cause', {
|
|
25
|
+
// I'd love to do _anyToError(opt.cause) here, but it causes circular dep ;(
|
|
26
|
+
value: opt.cause,
|
|
27
|
+
writable: true,
|
|
28
|
+
configurable: true,
|
|
29
|
+
enumerable: false,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
23
32
|
// todo: check if it's needed at all!
|
|
24
33
|
// if (Error.captureStackTrace) {
|
|
25
34
|
// Error.captureStackTrace(this, this.constructor)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { _jsonParseIfPossible, _stringifyAny } from '..';
|
|
2
2
|
/**
|
|
3
3
|
* Useful to ensure that error in `catch (err) { ... }`
|
|
4
4
|
* is indeed an Error (and not e.g `string` or `undefined`).
|
|
@@ -70,9 +70,6 @@ export function _errorToErrorObject(e) {
|
|
|
70
70
|
}
|
|
71
71
|
return obj;
|
|
72
72
|
}
|
|
73
|
-
export function _errorObjectToAppError(o) {
|
|
74
|
-
return _errorObjectToError(o, AppError);
|
|
75
|
-
}
|
|
76
73
|
export function _errorObjectToError(o, errorClass = Error) {
|
|
77
74
|
if (o instanceof errorClass)
|
|
78
75
|
return o;
|
package/package.json
CHANGED
package/src/error/app.error.ts
CHANGED
|
@@ -12,8 +12,13 @@ import type { ErrorData } from './error.model'
|
|
|
12
12
|
export class AppError<DATA_TYPE extends ErrorData = ErrorData> extends Error {
|
|
13
13
|
data!: DATA_TYPE
|
|
14
14
|
|
|
15
|
+
/**
|
|
16
|
+
* cause here is normalized to be instance of Error
|
|
17
|
+
*/
|
|
18
|
+
override cause?: Error
|
|
19
|
+
|
|
15
20
|
constructor(message: string, data = {} as DATA_TYPE, opt?: ErrorOptions) {
|
|
16
|
-
super(message
|
|
21
|
+
super(message)
|
|
17
22
|
|
|
18
23
|
Object.defineProperty(this, 'name', {
|
|
19
24
|
value: this.constructor.name,
|
|
@@ -27,6 +32,16 @@ export class AppError<DATA_TYPE extends ErrorData = ErrorData> extends Error {
|
|
|
27
32
|
enumerable: false,
|
|
28
33
|
})
|
|
29
34
|
|
|
35
|
+
if (opt?.cause) {
|
|
36
|
+
Object.defineProperty(this, 'cause', {
|
|
37
|
+
// I'd love to do _anyToError(opt.cause) here, but it causes circular dep ;(
|
|
38
|
+
value: opt.cause,
|
|
39
|
+
writable: true,
|
|
40
|
+
configurable: true,
|
|
41
|
+
enumerable: false,
|
|
42
|
+
})
|
|
43
|
+
}
|
|
44
|
+
|
|
30
45
|
// todo: check if it's needed at all!
|
|
31
46
|
// if (Error.captureStackTrace) {
|
|
32
47
|
// Error.captureStackTrace(this, this.constructor)
|
package/src/error/error.model.ts
CHANGED
package/src/error/error.util.ts
CHANGED
|
@@ -53,7 +53,7 @@ export function _anyToErrorObject<DATA_TYPE extends ErrorData = ErrorData>(
|
|
|
53
53
|
o = _jsonParseIfPossible(o)
|
|
54
54
|
|
|
55
55
|
if (_isHttpErrorResponse(o)) {
|
|
56
|
-
eo = o.error as
|
|
56
|
+
eo = o.error as ErrorObject<DATA_TYPE>
|
|
57
57
|
} else if (_isErrorObject(o)) {
|
|
58
58
|
eo = o as ErrorObject<DATA_TYPE>
|
|
59
59
|
} else {
|
|
@@ -92,12 +92,6 @@ export function _errorToErrorObject<DATA_TYPE extends ErrorData = ErrorData>(
|
|
|
92
92
|
return obj
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
-
export function _errorObjectToAppError<DATA_TYPE extends ErrorData>(
|
|
96
|
-
o: ErrorObject<DATA_TYPE>,
|
|
97
|
-
): AppError<DATA_TYPE> {
|
|
98
|
-
return _errorObjectToError(o, AppError)
|
|
99
|
-
}
|
|
100
|
-
|
|
101
95
|
export function _errorObjectToError<DATA_TYPE extends ErrorData, ERROR_TYPE extends Error>(
|
|
102
96
|
o: ErrorObject<DATA_TYPE>,
|
|
103
97
|
errorClass: Class<ERROR_TYPE> = Error as any,
|