@zerospin/error 2.1.0 → 2.1.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/package.json +1 -1
- package/src/ZerospinError.ts +9 -10
package/package.json
CHANGED
package/src/ZerospinError.ts
CHANGED
|
@@ -13,33 +13,32 @@ export type IAnyErrorJson<ERROR extends IAnyError = IAnyError> =
|
|
|
13
13
|
|
|
14
14
|
export type IAnyError = ZerospinError<string>;
|
|
15
15
|
|
|
16
|
-
interface IProps<T extends string = string,
|
|
16
|
+
interface IProps<T extends string = string, > {
|
|
17
17
|
code: T;
|
|
18
18
|
cause?: unknown;
|
|
19
|
-
extra?:
|
|
19
|
+
extra?: Record<string, unknown>;
|
|
20
20
|
message?: string;
|
|
21
21
|
status?: null | number;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
export interface IError<T extends string = string,
|
|
24
|
+
export interface IError<T extends string = string, > {
|
|
25
25
|
code: T;
|
|
26
26
|
status: null | number;
|
|
27
27
|
cause?: unknown;
|
|
28
|
-
extra?:
|
|
28
|
+
extra?: null | Record<string, unknown>;
|
|
29
29
|
message?: string;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
export class ZerospinError<
|
|
33
33
|
T extends string = never,
|
|
34
|
-
|
|
35
|
-
> extends Data.TaggedError('ZerospinError')<IError<T, E>> {
|
|
34
|
+
> extends Data.TaggedError('ZerospinError')<IError<T>> {
|
|
36
35
|
public override message!: string;
|
|
37
36
|
|
|
38
|
-
constructor(props: IProps<T
|
|
37
|
+
constructor(props: IProps<T> | T) {
|
|
39
38
|
if (typeof props === 'string') {
|
|
40
39
|
super({
|
|
41
40
|
code: props,
|
|
42
|
-
extra: null
|
|
41
|
+
extra: null,
|
|
43
42
|
message: props,
|
|
44
43
|
status: null,
|
|
45
44
|
});
|
|
@@ -60,7 +59,7 @@ export class ZerospinError<
|
|
|
60
59
|
static makeZerospinErrorJson(props: {
|
|
61
60
|
cause: unknown;
|
|
62
61
|
code: string;
|
|
63
|
-
extra: unknown
|
|
62
|
+
extra: null | Record<string, unknown>;
|
|
64
63
|
message: string;
|
|
65
64
|
status: null | number;
|
|
66
65
|
}): IAnyErrorJson {
|
|
@@ -74,7 +73,7 @@ export class ZerospinError<
|
|
|
74
73
|
const json = ZerospinError.makeZerospinErrorJson({
|
|
75
74
|
cause: this.cause,
|
|
76
75
|
code: this.code,
|
|
77
|
-
extra: this.extra,
|
|
76
|
+
extra: this.extra ?? null,
|
|
78
77
|
message: this.message,
|
|
79
78
|
status: this.status,
|
|
80
79
|
});
|