@dxos/errors 0.8.4-main.84f28bd → 0.8.4-main.b97322e
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/lib/browser/index.mjs +19 -0
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +19 -0
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/base.d.ts +35 -10
- package/dist/types/src/base.d.ts.map +1 -1
- package/dist/types/src/errors.d.ts +276 -30
- package/dist/types/src/errors.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/base.ts +27 -6
package/package.json
CHANGED
package/src/base.ts
CHANGED
|
@@ -15,25 +15,41 @@ export type BaseErrorOptions = {
|
|
|
15
15
|
context?: Record<string, unknown>;
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Base class for all DXOS errors.
|
|
20
|
+
*/
|
|
21
|
+
export class BaseError<Code extends string = string> extends Error {
|
|
22
|
+
/**
|
|
23
|
+
* Primary way of defining new error classes.
|
|
24
|
+
*
|
|
25
|
+
* Expample:
|
|
26
|
+
*
|
|
27
|
+
* ```ts
|
|
28
|
+
* export class AiInputPreprocessingError extends BaseError.extend('AI_INPUT_PREPROCESSING_ERROR') {}
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
static extend<Code extends string>(code: Code) {
|
|
32
|
+
return class extends BaseError<Code> {
|
|
21
33
|
static code = code;
|
|
22
34
|
|
|
23
35
|
static is(error: unknown): error is BaseError {
|
|
24
36
|
return typeof error === 'object' && error !== null && 'code' in error && error.code === code;
|
|
25
37
|
}
|
|
26
38
|
|
|
39
|
+
static wrap(message: string, options?: Omit<BaseErrorOptions, 'cause'>) {
|
|
40
|
+
return (error: unknown) => new this(message, { ...options, cause: error });
|
|
41
|
+
}
|
|
42
|
+
|
|
27
43
|
constructor(message: string, options?: BaseErrorOptions) {
|
|
28
44
|
super(code, message, options);
|
|
29
45
|
}
|
|
30
46
|
};
|
|
31
47
|
}
|
|
32
48
|
|
|
33
|
-
#code:
|
|
49
|
+
#code: Code;
|
|
34
50
|
#context: Record<string, unknown>;
|
|
35
51
|
|
|
36
|
-
constructor(code:
|
|
52
|
+
constructor(code: Code, message: string, options?: BaseErrorOptions) {
|
|
37
53
|
super(message, options);
|
|
38
54
|
|
|
39
55
|
this.#code = code;
|
|
@@ -45,7 +61,12 @@ export class BaseError extends Error {
|
|
|
45
61
|
return this.#code;
|
|
46
62
|
}
|
|
47
63
|
|
|
48
|
-
get code() {
|
|
64
|
+
get code(): Code {
|
|
65
|
+
return this.#code;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// For effect error matching.
|
|
69
|
+
get _tag(): Code {
|
|
49
70
|
return this.#code;
|
|
50
71
|
}
|
|
51
72
|
|