@sprucelabs/error 5.0.454 → 5.0.455
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.
|
@@ -14,6 +14,6 @@ export default abstract class AbstractSpruceError<T extends ErrorOptions = Spruc
|
|
|
14
14
|
prettyPrint(): string;
|
|
15
15
|
static parse<T extends {
|
|
16
16
|
prototype: any;
|
|
17
|
-
}>(json: string | Record<string, any
|
|
17
|
+
}>(json: string | Record<string, any> | Error | AbstractSpruceError, ClassRef: T): MyInstanceType<T>;
|
|
18
18
|
}
|
|
19
19
|
export {};
|
|
@@ -64,6 +64,19 @@ class AbstractSpruceError extends Error {
|
|
|
64
64
|
return this.message + '\n\n' + this.stack;
|
|
65
65
|
}
|
|
66
66
|
static parse(json, ClassRef) {
|
|
67
|
+
if (json instanceof AbstractSpruceError) {
|
|
68
|
+
return json;
|
|
69
|
+
}
|
|
70
|
+
if (json instanceof Error) {
|
|
71
|
+
//@ts-ignore
|
|
72
|
+
const err = new ClassRef({
|
|
73
|
+
code: 'UNKNOWN_ERROR',
|
|
74
|
+
friendlyMessage: json.message,
|
|
75
|
+
originalError: json,
|
|
76
|
+
});
|
|
77
|
+
err.stack = json.stack;
|
|
78
|
+
return err;
|
|
79
|
+
}
|
|
67
80
|
try {
|
|
68
81
|
const { options, stack } = typeof json === 'string' ? JSON.parse(json) : json;
|
|
69
82
|
// @ts-ignore
|
|
@@ -14,6 +14,6 @@ export default abstract class AbstractSpruceError<T extends ErrorOptions = Spruc
|
|
|
14
14
|
prettyPrint(): string;
|
|
15
15
|
static parse<T extends {
|
|
16
16
|
prototype: any;
|
|
17
|
-
}>(json: string | Record<string, any
|
|
17
|
+
}>(json: string | Record<string, any> | Error | AbstractSpruceError, ClassRef: T): MyInstanceType<T>;
|
|
18
18
|
}
|
|
19
19
|
export {};
|
|
@@ -62,6 +62,19 @@ export default class AbstractSpruceError extends Error {
|
|
|
62
62
|
return this.message + '\n\n' + this.stack;
|
|
63
63
|
}
|
|
64
64
|
static parse(json, ClassRef) {
|
|
65
|
+
if (json instanceof AbstractSpruceError) {
|
|
66
|
+
return json;
|
|
67
|
+
}
|
|
68
|
+
if (json instanceof Error) {
|
|
69
|
+
//@ts-ignore
|
|
70
|
+
const err = new ClassRef({
|
|
71
|
+
code: 'UNKNOWN_ERROR',
|
|
72
|
+
friendlyMessage: json.message,
|
|
73
|
+
originalError: json,
|
|
74
|
+
});
|
|
75
|
+
err.stack = json.stack;
|
|
76
|
+
return err;
|
|
77
|
+
}
|
|
65
78
|
try {
|
|
66
79
|
const { options, stack } = typeof json === 'string' ? JSON.parse(json) : json;
|
|
67
80
|
// @ts-ignore
|