@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 CHANGED
@@ -21,3 +21,4 @@ export * from './not-supported.error.js';
21
21
  export * from './timeout.error.js';
22
22
  export * from './unauthorized.error.js';
23
23
  export * from './unsupported-media-type.error.js';
24
+ export * from './utils.js';
package/errors/index.js CHANGED
@@ -21,3 +21,4 @@ export * from './not-supported.error.js';
21
21
  export * from './timeout.error.js';
22
22
  export * from './unauthorized.error.js';
23
23
  export * from './unsupported-media-type.error.js';
24
+ export * from './utils.js';
@@ -0,0 +1 @@
1
+ export declare function unwrapError(error: any): any;
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tstdl/base",
3
- "version": "0.90.2",
3
+ "version": "0.90.3",
4
4
  "author": "Patrick Hein",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -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
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
13
- const wrappedError = error?.rejection ?? error?.reason ?? error?.error;
14
- if ((error instanceof Error) && !(error.message.startsWith('Uncaught') && (wrappedError instanceof Error))) {
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(error.getExtraInfo)) {
18
- extraInfo = error.getExtraInfo();
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(error);
23
+ const decycledError = decycle(actualError);
27
24
  message = JSON.stringify(decycledError, null, 2);
28
25
  }
29
26
  catch {
30
- throw error;
27
+ throw actualError;
31
28
  }
32
29
  }
33
30
  const nameString = (options.includeName ?? true) ? `${name ?? 'Error'}: ` : '';