@tstdl/base 0.90.2 → 0.90.3
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/errors/index.d.ts +1 -0
- package/errors/index.js +1 -0
- package/errors/utils.d.ts +1 -0
- package/errors/utils.js +8 -0
- package/package.json +1 -1
- package/utils/format-error.js +8 -11
package/errors/index.d.ts
CHANGED
package/errors/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function unwrapError(error: any): any;
|
package/errors/utils.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export function unwrapError(error) {
|
|
2
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
3
|
+
const wrappedError = error?.rejection ?? error?.reason ?? error?.error;
|
|
4
|
+
if ((error instanceof Error) && !(error.message.startsWith('Uncaught') && (wrappedError instanceof Error))) {
|
|
5
|
+
return error;
|
|
6
|
+
}
|
|
7
|
+
return wrappedError;
|
|
8
|
+
}
|
package/package.json
CHANGED
package/utils/format-error.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { unwrapError } from '../errors/utils.js';
|
|
1
2
|
import { decycle } from './object/decycle.js';
|
|
2
3
|
import { objectKeys } from './object/object.js';
|
|
3
4
|
import { isDefined, isFunction, isUndefined } from './type-guards.js';
|
|
@@ -9,25 +10,21 @@ export function formatError(error, options = {}) {
|
|
|
9
10
|
let stack;
|
|
10
11
|
let rest;
|
|
11
12
|
let extraInfo;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
({ name, message, stack, ...rest } = error);
|
|
13
|
+
const actualError = unwrapError(error);
|
|
14
|
+
if ((actualError instanceof Error)) {
|
|
15
|
+
({ name, message, stack, ...rest } = actualError);
|
|
16
16
|
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
17
|
-
if (includeExtraInfo && isFunction(
|
|
18
|
-
extraInfo =
|
|
17
|
+
if (includeExtraInfo && isFunction(actualError.getExtraInfo)) {
|
|
18
|
+
extraInfo = actualError.getExtraInfo();
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
-
else if (wrappedError instanceof Error) {
|
|
22
|
-
return formatError(wrappedError, options);
|
|
23
|
-
}
|
|
24
21
|
if (isUndefined(name) && (isUndefined(message) || message.trim().length == 0)) {
|
|
25
22
|
try {
|
|
26
|
-
const decycledError = decycle(
|
|
23
|
+
const decycledError = decycle(actualError);
|
|
27
24
|
message = JSON.stringify(decycledError, null, 2);
|
|
28
25
|
}
|
|
29
26
|
catch {
|
|
30
|
-
throw
|
|
27
|
+
throw actualError;
|
|
31
28
|
}
|
|
32
29
|
}
|
|
33
30
|
const nameString = (options.includeName ?? true) ? `${name ?? 'Error'}: ` : '';
|