@naturalcycles/js-lib 14.124.0 → 14.124.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/error.util.js +17 -6
- package/dist-esm/error/error.util.js +14 -6
- package/package.json +1 -1
- package/src/error/error.util.ts +17 -5
package/dist/error/error.util.js
CHANGED
|
@@ -11,12 +11,23 @@ const __1 = require("..");
|
|
|
11
11
|
* Alternatively, if you're sure it's Error - you can use `_assertIsError(err)`.
|
|
12
12
|
*/
|
|
13
13
|
function _anyToError(o, errorClass = Error, errorData, opt) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
let e;
|
|
15
|
+
if (o instanceof errorClass) {
|
|
16
|
+
e = o;
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
// If it's an instance of Error, but ErrorClass is something else (e.g AppError) - it'll be "repacked" into AppError
|
|
20
|
+
const errorObject = _isErrorObject(o) ? o : _anyToErrorObject(o, {}, opt);
|
|
21
|
+
e = _errorObjectToError(errorObject, errorClass);
|
|
22
|
+
}
|
|
23
|
+
if (errorData) {
|
|
24
|
+
;
|
|
25
|
+
e.data = {
|
|
26
|
+
...e.data,
|
|
27
|
+
...errorData,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
return e;
|
|
20
31
|
}
|
|
21
32
|
exports._anyToError = _anyToError;
|
|
22
33
|
/**
|
|
@@ -8,12 +8,20 @@ import { AppError, _jsonParseIfPossible, _stringifyAny } from '..';
|
|
|
8
8
|
* Alternatively, if you're sure it's Error - you can use `_assertIsError(err)`.
|
|
9
9
|
*/
|
|
10
10
|
export function _anyToError(o, errorClass = Error, errorData, opt) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
let e;
|
|
12
|
+
if (o instanceof errorClass) {
|
|
13
|
+
e = o;
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
// If it's an instance of Error, but ErrorClass is something else (e.g AppError) - it'll be "repacked" into AppError
|
|
17
|
+
const errorObject = _isErrorObject(o) ? o : _anyToErrorObject(o, {}, opt);
|
|
18
|
+
e = _errorObjectToError(errorObject, errorClass);
|
|
19
|
+
}
|
|
20
|
+
if (errorData) {
|
|
21
|
+
;
|
|
22
|
+
e.data = Object.assign(Object.assign({}, e.data), errorData);
|
|
23
|
+
}
|
|
24
|
+
return e;
|
|
17
25
|
}
|
|
18
26
|
/**
|
|
19
27
|
* Converts "anything" to ErrorObject.
|
package/package.json
CHANGED
package/src/error/error.util.ts
CHANGED
|
@@ -22,13 +22,25 @@ export function _anyToError<ERROR_TYPE extends Error = Error>(
|
|
|
22
22
|
errorData?: ErrorData,
|
|
23
23
|
opt?: StringifyAnyOptions,
|
|
24
24
|
): ERROR_TYPE {
|
|
25
|
-
|
|
25
|
+
let e: ERROR_TYPE
|
|
26
|
+
|
|
27
|
+
if (o instanceof errorClass) {
|
|
28
|
+
e = o
|
|
29
|
+
} else {
|
|
30
|
+
// If it's an instance of Error, but ErrorClass is something else (e.g AppError) - it'll be "repacked" into AppError
|
|
26
31
|
|
|
27
|
-
|
|
32
|
+
const errorObject = _isErrorObject(o) ? o : _anyToErrorObject(o, {}, opt)
|
|
33
|
+
e = _errorObjectToError(errorObject, errorClass) as any
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (errorData) {
|
|
37
|
+
;(e as any).data = {
|
|
38
|
+
...(e as any).data,
|
|
39
|
+
...errorData,
|
|
40
|
+
}
|
|
41
|
+
}
|
|
28
42
|
|
|
29
|
-
|
|
30
|
-
Object.assign(errorObject.data, errorData)
|
|
31
|
-
return _errorObjectToError(errorObject, errorClass)
|
|
43
|
+
return e
|
|
32
44
|
}
|
|
33
45
|
|
|
34
46
|
/**
|