@alessiofrittoli/exception 4.1.1 → 4.3.0

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.
@@ -1,6 +1,5 @@
1
+ import { n as ExceptionOptions, t as Exception } from "../index-CAXMeOIU.cjs";
1
2
  import { ErrorCode } from "../code/index.cjs";
2
- import { Exception, ExceptionOptions } from "../index.cjs";
3
- //#region src/abort/index.d.ts
4
3
  /**
5
4
  * Interface representing the options for an Exception.
6
5
  *
@@ -25,5 +24,4 @@ export declare class AbortError<T = ErrorCode> extends Exception<T> implements A
25
24
  * @returns `true` if the error is an `AbortError` and has the ABORT ErrorCode, `false` otherwise.
26
25
  */
27
26
  static isAbortError<T = ErrorCode>(error: any, code?: T): error is AbortError<T>;
28
- }
29
- //#endregion
27
+ }
@@ -1,6 +1,5 @@
1
+ import { n as ExceptionOptions, t as Exception } from "../index-D_kjKA8h.mjs";
1
2
  import { ErrorCode } from "../code/index.mjs";
2
- import { Exception, ExceptionOptions } from "../index.mjs";
3
- //#region src/abort/index.d.ts
4
3
  /**
5
4
  * Interface representing the options for an Exception.
6
5
  *
@@ -25,5 +24,4 @@ export declare class AbortError<T = ErrorCode> extends Exception<T> implements A
25
24
  * @returns `true` if the error is an `AbortError` and has the ABORT ErrorCode, `false` otherwise.
26
25
  */
27
26
  static isAbortError<T = ErrorCode>(error: any, code?: T): error is AbortError<T>;
28
- }
29
- //#endregion
27
+ }
@@ -1,4 +1,3 @@
1
- //#region src/code/index.d.ts
2
1
  /**
3
2
  * Most common error codes.
4
3
  *
@@ -15,5 +14,4 @@ export declare const ErrorCode: {
15
14
  readonly NOT_FOUND: "ERR:NOTFOUND";
16
15
  readonly OFFLINE: "ERR:INTERNETDISCONNECTED";
17
16
  };
18
- export type ErrorCode = (typeof ErrorCode)[keyof typeof ErrorCode];
19
- //#endregion
17
+ export type ErrorCode = (typeof ErrorCode)[keyof typeof ErrorCode];
@@ -1,4 +1,3 @@
1
- //#region src/code/index.d.ts
2
1
  /**
3
2
  * Most common error codes.
4
3
  *
@@ -15,5 +14,4 @@ export declare const ErrorCode: {
15
14
  readonly NOT_FOUND: "ERR:NOTFOUND";
16
15
  readonly OFFLINE: "ERR:INTERNETDISCONNECTED";
17
16
  };
18
- export type ErrorCode = (typeof ErrorCode)[keyof typeof ErrorCode];
19
- //#endregion
17
+ export type ErrorCode = (typeof ErrorCode)[keyof typeof ErrorCode];
@@ -0,0 +1,240 @@
1
+ import { ErrorCode } from "./code/index.cjs";
2
+ /**
3
+ * Constructs a type by picking all properties from `T` and then removing `U`.
4
+ *
5
+ * This is a strict version of the built-in `Omit`. The built-in one declares its keys
6
+ * as `K extends keyof any`, so it accepts **any** string, number or symbol: a typo or a
7
+ * property removed/renamed from `T` is silently ignored and the omission becomes a no-op,
8
+ * with no editor autocompletion on the keys either.
9
+ *
10
+ * Constraining `U` to `keyof T` makes the compiler reject keys that don't exist on `T`,
11
+ * so omitted properties stay in sync with the source type when it changes.
12
+ *
13
+ * @template T The type/interface from which properties will be omitted.
14
+ * @template U The keys of `T` to omit.
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * interface User {
19
+ * id: string
20
+ * name: string
21
+ * }
22
+ *
23
+ * type A = globalThis.Omit<User, 'nmae'> // ✅ compiles, `name` is NOT omitted
24
+ * type B = Omit<User, 'nmae'> // ❌ Type '"nmae"' does not satisfy the constraint 'keyof User'.
25
+ * type C = Omit<User, 'name'> // ✅ `{ id: string }`
26
+ * ```
27
+ */
28
+ type Omit<T, U extends keyof T> = globalThis.Omit<T, U>;
29
+ /**
30
+ * Exception Name.
31
+ *
32
+ * [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/DOMException#error_names)
33
+ */
34
+ declare const ExceptionName: {
35
+ readonly Exception: "Exception";
36
+ readonly AbortError: "AbortError";
37
+ readonly NotAllowedError: "NotAllowedError";
38
+ readonly NotFoundError: "NotFoundError";
39
+ readonly NotSupportedError: "NotSupportedError";
40
+ readonly InvalidStateError: "InvalidStateError";
41
+ readonly InvalidAccessError: "InvalidAccessError";
42
+ readonly NetworkError: "NetworkError";
43
+ readonly SecurityError: "SecurityError";
44
+ readonly TimeoutError: "TimeoutError";
45
+ readonly QuotaExceededError: "QuotaExceededError";
46
+ readonly DataError: "DataError";
47
+ readonly EncodingError: "EncodingError";
48
+ readonly OperationError: "OperationError";
49
+ readonly ConstraintError: "ConstraintError";
50
+ readonly TransactionInactiveError: "TransactionInactiveError";
51
+ readonly ReadOnlyError: "ReadOnlyError";
52
+ readonly VersionError: "VersionError";
53
+ readonly NoModificationAllowedError: "NoModificationAllowedError";
54
+ readonly HierarchyRequestError: "HierarchyRequestError";
55
+ readonly WrongDocumentError: "WrongDocumentError";
56
+ readonly InvalidCharacterError: "InvalidCharacterError";
57
+ readonly NamespaceError: "NamespaceError";
58
+ readonly SyntaxError: "SyntaxError";
59
+ readonly DataCloneError: "DataCloneError";
60
+ readonly URLMismatchError: "URLMismatchError";
61
+ readonly InvalidModificationError: "InvalidModificationError";
62
+ readonly NotReadableError: "NotReadableError";
63
+ };
64
+ type ExceptionName = (typeof ExceptionName)[keyof typeof ExceptionName];
65
+ /**
66
+ * The `Exception` severity.
67
+ *
68
+ */
69
+ type Severity = typeof Exception.RECOVERABLE | typeof Exception.SEVERE | typeof Exception.CRITICAL;
70
+ interface JSONException<T = ErrorCode> extends Omit<Exception<T>, 'toJSON'> {
71
+ Symbol: typeof ExceptionName.Exception;
72
+ }
73
+ /**
74
+ * Interface representing the options for an Exception.
75
+ *
76
+ * @template T The type of the error code.
77
+ *
78
+ * @extends ErrorOptions
79
+ */
80
+ interface ExceptionOptions<T = ErrorCode> extends ErrorOptions {
81
+ /**
82
+ * The error interface name.
83
+ *
84
+ * @see {@link ExceptionName} for a list of possible standard values.
85
+ *
86
+ * @default ExceptionName.Exception
87
+ */
88
+ name?: string;
89
+ /**
90
+ * The error message containing technical informations about the error.
91
+ *
92
+ * It shouldn't be rendered to the user.
93
+ */
94
+ message?: string;
95
+ /**
96
+ * The error title.
97
+ *
98
+ */
99
+ title?: string;
100
+ /**
101
+ * The error description.
102
+ *
103
+ */
104
+ description?: string;
105
+ /**
106
+ * The error code associated with the Exception.
107
+ *
108
+ */
109
+ code: T;
110
+ /**
111
+ * Indicates whether the error is a critical error.
112
+ *
113
+ * @default false
114
+ */
115
+ isCritical?: boolean;
116
+ /**
117
+ * Indicates the error severity.
118
+ *
119
+ */
120
+ severity?: Severity;
121
+ /**
122
+ * The HTTP status code associated with the Exception.
123
+ *
124
+ */
125
+ status?: number;
126
+ /**
127
+ * The error cause.
128
+ *
129
+ */
130
+ cause?: unknown;
131
+ }
132
+ /**
133
+ * Exception Class.
134
+ *
135
+ * @template T The type of the code property of the Exception. Defaults to `ErrorCode`.
136
+ *
137
+ * @extends Error
138
+ */
139
+ declare class Exception<T = ErrorCode> extends Error {
140
+ static readonly Symbol: unique symbol;
141
+ /**
142
+ * The error interface name.
143
+ *
144
+ */
145
+ readonly name: string;
146
+ /**
147
+ * The error message containing technical informations about the error.
148
+ *
149
+ * ⚠️ do not render `Exception.message` to the user.
150
+ */
151
+ readonly message: string;
152
+ /**
153
+ * The error title that can be rendered to the user.
154
+ *
155
+ */
156
+ readonly title: string | undefined;
157
+ /**
158
+ * The error description that can be rendered to the user.
159
+ *
160
+ */
161
+ readonly description: string | undefined;
162
+ /**
163
+ * The error code.
164
+ *
165
+ */
166
+ readonly code: T;
167
+ /**
168
+ * The HTTP status code associated with the Exception.
169
+ *
170
+ */
171
+ readonly status: number | undefined;
172
+ /**
173
+ * The error cause.
174
+ *
175
+ */
176
+ readonly cause: unknown;
177
+ /**
178
+ * The error severity.
179
+ *
180
+ */
181
+ readonly severity?: Severity;
182
+ /**
183
+ * Indicates whether the `Exception.severity` is critical.
184
+ *
185
+ */
186
+ readonly isCritical: boolean;
187
+ /**
188
+ * A non-critical error that could be resolved by retrying the algorithm maybe with different parameters.
189
+ *
190
+ */
191
+ static readonly RECOVERABLE = 1;
192
+ /**
193
+ * An error that interrupted some algorithms but the overall system still works.
194
+ *
195
+ */
196
+ static readonly SEVERE = 2;
197
+ /**
198
+ * An error that interrupts the algorithm.
199
+ *
200
+ */
201
+ static readonly CRITICAL = 3;
202
+ /**
203
+ * Constructs a new Exception instance.
204
+ *
205
+ * @param options An object defining Exception options. See {@link ExceptionOptions} for more info.
206
+ */
207
+ constructor(options: ExceptionOptions<T>);
208
+ /**
209
+ * Determines if the provided error is an instance of the Exception class.
210
+ *
211
+ * @template T The type of the code property of the Exception.
212
+ *
213
+ * @param error The error to check.
214
+ * @returns `true` if the error is an instance of Exception or has a `__typename` property equal to 'Exception', `false` otherwise.
215
+ */
216
+ static isException<T = ErrorCode>(error: unknown): error is Exception<T> | JSONException<T>;
217
+ /**
218
+ * Determines if the provided error is an instance of the Exception class and has the ABORT ErrorCode.
219
+ *
220
+ * @template T The type of the code property of the Exception.
221
+ *
222
+ * @param error The error to check.
223
+ * @returns `true` if the error is an `Exception` and has the ABORT ErrorCode, `false` otherwise.
224
+ */
225
+ static isAbortError<T = ErrorCode>(error: any, code?: T): error is Exception<T>;
226
+ /**
227
+ * Converts the instance to a JSON object.
228
+ *
229
+ * @returns A JSON representation of the instance, including the message property.
230
+ */
231
+ toJSON(): JSONException<T>;
232
+ /**
233
+ * Attempts to normalize the given `cause` to a possible `Exception` instance.
234
+ *
235
+ * @param cause The error cause.
236
+ * @returns The cause as `Exception` instance if applicable, the given cause as is (`unknown`) otherwise.
237
+ */
238
+ private static normalizeCause;
239
+ }
240
+ export { ExceptionName as a, Severity as i, ExceptionOptions as n, JSONException as r, Exception as t };
@@ -0,0 +1,240 @@
1
+ import { ErrorCode } from "./code/index.mjs";
2
+ /**
3
+ * Constructs a type by picking all properties from `T` and then removing `U`.
4
+ *
5
+ * This is a strict version of the built-in `Omit`. The built-in one declares its keys
6
+ * as `K extends keyof any`, so it accepts **any** string, number or symbol: a typo or a
7
+ * property removed/renamed from `T` is silently ignored and the omission becomes a no-op,
8
+ * with no editor autocompletion on the keys either.
9
+ *
10
+ * Constraining `U` to `keyof T` makes the compiler reject keys that don't exist on `T`,
11
+ * so omitted properties stay in sync with the source type when it changes.
12
+ *
13
+ * @template T The type/interface from which properties will be omitted.
14
+ * @template U The keys of `T` to omit.
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * interface User {
19
+ * id: string
20
+ * name: string
21
+ * }
22
+ *
23
+ * type A = globalThis.Omit<User, 'nmae'> // ✅ compiles, `name` is NOT omitted
24
+ * type B = Omit<User, 'nmae'> // ❌ Type '"nmae"' does not satisfy the constraint 'keyof User'.
25
+ * type C = Omit<User, 'name'> // ✅ `{ id: string }`
26
+ * ```
27
+ */
28
+ type Omit<T, U extends keyof T> = globalThis.Omit<T, U>;
29
+ /**
30
+ * Exception Name.
31
+ *
32
+ * [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/DOMException#error_names)
33
+ */
34
+ declare const ExceptionName: {
35
+ readonly Exception: "Exception";
36
+ readonly AbortError: "AbortError";
37
+ readonly NotAllowedError: "NotAllowedError";
38
+ readonly NotFoundError: "NotFoundError";
39
+ readonly NotSupportedError: "NotSupportedError";
40
+ readonly InvalidStateError: "InvalidStateError";
41
+ readonly InvalidAccessError: "InvalidAccessError";
42
+ readonly NetworkError: "NetworkError";
43
+ readonly SecurityError: "SecurityError";
44
+ readonly TimeoutError: "TimeoutError";
45
+ readonly QuotaExceededError: "QuotaExceededError";
46
+ readonly DataError: "DataError";
47
+ readonly EncodingError: "EncodingError";
48
+ readonly OperationError: "OperationError";
49
+ readonly ConstraintError: "ConstraintError";
50
+ readonly TransactionInactiveError: "TransactionInactiveError";
51
+ readonly ReadOnlyError: "ReadOnlyError";
52
+ readonly VersionError: "VersionError";
53
+ readonly NoModificationAllowedError: "NoModificationAllowedError";
54
+ readonly HierarchyRequestError: "HierarchyRequestError";
55
+ readonly WrongDocumentError: "WrongDocumentError";
56
+ readonly InvalidCharacterError: "InvalidCharacterError";
57
+ readonly NamespaceError: "NamespaceError";
58
+ readonly SyntaxError: "SyntaxError";
59
+ readonly DataCloneError: "DataCloneError";
60
+ readonly URLMismatchError: "URLMismatchError";
61
+ readonly InvalidModificationError: "InvalidModificationError";
62
+ readonly NotReadableError: "NotReadableError";
63
+ };
64
+ type ExceptionName = (typeof ExceptionName)[keyof typeof ExceptionName];
65
+ /**
66
+ * The `Exception` severity.
67
+ *
68
+ */
69
+ type Severity = typeof Exception.RECOVERABLE | typeof Exception.SEVERE | typeof Exception.CRITICAL;
70
+ interface JSONException<T = ErrorCode> extends Omit<Exception<T>, 'toJSON'> {
71
+ Symbol: typeof ExceptionName.Exception;
72
+ }
73
+ /**
74
+ * Interface representing the options for an Exception.
75
+ *
76
+ * @template T The type of the error code.
77
+ *
78
+ * @extends ErrorOptions
79
+ */
80
+ interface ExceptionOptions<T = ErrorCode> extends ErrorOptions {
81
+ /**
82
+ * The error interface name.
83
+ *
84
+ * @see {@link ExceptionName} for a list of possible standard values.
85
+ *
86
+ * @default ExceptionName.Exception
87
+ */
88
+ name?: string;
89
+ /**
90
+ * The error message containing technical informations about the error.
91
+ *
92
+ * It shouldn't be rendered to the user.
93
+ */
94
+ message?: string;
95
+ /**
96
+ * The error title.
97
+ *
98
+ */
99
+ title?: string;
100
+ /**
101
+ * The error description.
102
+ *
103
+ */
104
+ description?: string;
105
+ /**
106
+ * The error code associated with the Exception.
107
+ *
108
+ */
109
+ code: T;
110
+ /**
111
+ * Indicates whether the error is a critical error.
112
+ *
113
+ * @default false
114
+ */
115
+ isCritical?: boolean;
116
+ /**
117
+ * Indicates the error severity.
118
+ *
119
+ */
120
+ severity?: Severity;
121
+ /**
122
+ * The HTTP status code associated with the Exception.
123
+ *
124
+ */
125
+ status?: number;
126
+ /**
127
+ * The error cause.
128
+ *
129
+ */
130
+ cause?: unknown;
131
+ }
132
+ /**
133
+ * Exception Class.
134
+ *
135
+ * @template T The type of the code property of the Exception. Defaults to `ErrorCode`.
136
+ *
137
+ * @extends Error
138
+ */
139
+ declare class Exception<T = ErrorCode> extends Error {
140
+ static readonly Symbol: unique symbol;
141
+ /**
142
+ * The error interface name.
143
+ *
144
+ */
145
+ readonly name: string;
146
+ /**
147
+ * The error message containing technical informations about the error.
148
+ *
149
+ * ⚠️ do not render `Exception.message` to the user.
150
+ */
151
+ readonly message: string;
152
+ /**
153
+ * The error title that can be rendered to the user.
154
+ *
155
+ */
156
+ readonly title: string | undefined;
157
+ /**
158
+ * The error description that can be rendered to the user.
159
+ *
160
+ */
161
+ readonly description: string | undefined;
162
+ /**
163
+ * The error code.
164
+ *
165
+ */
166
+ readonly code: T;
167
+ /**
168
+ * The HTTP status code associated with the Exception.
169
+ *
170
+ */
171
+ readonly status: number | undefined;
172
+ /**
173
+ * The error cause.
174
+ *
175
+ */
176
+ readonly cause: unknown;
177
+ /**
178
+ * The error severity.
179
+ *
180
+ */
181
+ readonly severity?: Severity;
182
+ /**
183
+ * Indicates whether the `Exception.severity` is critical.
184
+ *
185
+ */
186
+ readonly isCritical: boolean;
187
+ /**
188
+ * A non-critical error that could be resolved by retrying the algorithm maybe with different parameters.
189
+ *
190
+ */
191
+ static readonly RECOVERABLE = 1;
192
+ /**
193
+ * An error that interrupted some algorithms but the overall system still works.
194
+ *
195
+ */
196
+ static readonly SEVERE = 2;
197
+ /**
198
+ * An error that interrupts the algorithm.
199
+ *
200
+ */
201
+ static readonly CRITICAL = 3;
202
+ /**
203
+ * Constructs a new Exception instance.
204
+ *
205
+ * @param options An object defining Exception options. See {@link ExceptionOptions} for more info.
206
+ */
207
+ constructor(options: ExceptionOptions<T>);
208
+ /**
209
+ * Determines if the provided error is an instance of the Exception class.
210
+ *
211
+ * @template T The type of the code property of the Exception.
212
+ *
213
+ * @param error The error to check.
214
+ * @returns `true` if the error is an instance of Exception or has a `__typename` property equal to 'Exception', `false` otherwise.
215
+ */
216
+ static isException<T = ErrorCode>(error: unknown): error is Exception<T> | JSONException<T>;
217
+ /**
218
+ * Determines if the provided error is an instance of the Exception class and has the ABORT ErrorCode.
219
+ *
220
+ * @template T The type of the code property of the Exception.
221
+ *
222
+ * @param error The error to check.
223
+ * @returns `true` if the error is an `Exception` and has the ABORT ErrorCode, `false` otherwise.
224
+ */
225
+ static isAbortError<T = ErrorCode>(error: any, code?: T): error is Exception<T>;
226
+ /**
227
+ * Converts the instance to a JSON object.
228
+ *
229
+ * @returns A JSON representation of the instance, including the message property.
230
+ */
231
+ toJSON(): JSONException<T>;
232
+ /**
233
+ * Attempts to normalize the given `cause` to a possible `Exception` instance.
234
+ *
235
+ * @param cause The error cause.
236
+ * @returns The cause as `Exception` instance if applicable, the given cause as is (`unknown`) otherwise.
237
+ */
238
+ private static normalizeCause;
239
+ }
240
+ export { ExceptionName as a, Severity as i, ExceptionOptions as n, JSONException as r, Exception as t };
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./code/index.cjs"),t={Exception:`Exception`,AbortError:`AbortError`,NotAllowedError:`NotAllowedError`,NotFoundError:`NotFoundError`,NotSupportedError:`NotSupportedError`,InvalidStateError:`InvalidStateError`,InvalidAccessError:`InvalidAccessError`,NetworkError:`NetworkError`,SecurityError:`SecurityError`,TimeoutError:`TimeoutError`,QuotaExceededError:`QuotaExceededError`,DataError:`DataError`,EncodingError:`EncodingError`,OperationError:`OperationError`,ConstraintError:`ConstraintError`,TransactionInactiveError:`TransactionInactiveError`,ReadOnlyError:`ReadOnlyError`,VersionError:`VersionError`,NoModificationAllowedError:`NoModificationAllowedError`,HierarchyRequestError:`HierarchyRequestError`,WrongDocumentError:`WrongDocumentError`,InvalidCharacterError:`InvalidCharacterError`,NamespaceError:`NamespaceError`,SyntaxError:`SyntaxError`,DataCloneError:`DataCloneError`,URLMismatchError:`URLMismatchError`,InvalidModificationError:`InvalidModificationError`,NotReadableError:`NotReadableError`};var n=class n extends Error{__typename=t.Exception;name=this.__typename;message;title;description;code;isCritical;status;cause;constructor(e){let{message:t=`Unknown error.`}=e;super(t),e.name&&(this.name=e.name),this.message=t,this.title=e.title,this.description=e.description,this.code=e.code,this.isCritical=e.isCritical??!1,this.status=e.status,this.cause=n.isException(e.cause)?new n(e.cause):e.cause}static isException(e){return e instanceof n||!!e&&typeof e==`object`&&`__typename`in e&&e.__typename===t.Exception}static isAbortError(r,i=e.ErrorCode.ABORT){return n.isException(r)&&(r.name===t.AbortError||r.code===i)}toJSON(){return{...this,message:this.message,cause:this.cause}}};exports.Exception=n,exports.ExceptionName=t;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./code/index.cjs"),t={Exception:`Exception`,AbortError:`AbortError`,NotAllowedError:`NotAllowedError`,NotFoundError:`NotFoundError`,NotSupportedError:`NotSupportedError`,InvalidStateError:`InvalidStateError`,InvalidAccessError:`InvalidAccessError`,NetworkError:`NetworkError`,SecurityError:`SecurityError`,TimeoutError:`TimeoutError`,QuotaExceededError:`QuotaExceededError`,DataError:`DataError`,EncodingError:`EncodingError`,OperationError:`OperationError`,ConstraintError:`ConstraintError`,TransactionInactiveError:`TransactionInactiveError`,ReadOnlyError:`ReadOnlyError`,VersionError:`VersionError`,NoModificationAllowedError:`NoModificationAllowedError`,HierarchyRequestError:`HierarchyRequestError`,WrongDocumentError:`WrongDocumentError`,InvalidCharacterError:`InvalidCharacterError`,NamespaceError:`NamespaceError`,SyntaxError:`SyntaxError`,DataCloneError:`DataCloneError`,URLMismatchError:`URLMismatchError`,InvalidModificationError:`InvalidModificationError`,NotReadableError:`NotReadableError`};var n=class n extends Error{static Symbol=Symbol.for(t.Exception);name=t.Exception;message;title;description;code;status;cause;severity;isCritical;static RECOVERABLE=1;static SEVERE=2;static CRITICAL=3;constructor(e){let{message:t=`Unknown error.`}=e;super(t),e.name&&(this.name=e.name);let{isCritical:r,severity:i=r?n.CRITICAL:void 0}=e;this.message=t,this.title=e.title,this.description=e.description,this.code=e.code,this.severity=i,this.isCritical=r??this.severity===n.CRITICAL,this.status=e.status,this.cause=n.normalizeCause(e.cause)}static isException(e){return!e||typeof e!=`object`?!1:e instanceof n?!0:`Symbol`in e?e.Symbol===n.Symbol||typeof e.Symbol==`string`&&Symbol.for(e.Symbol)===n.Symbol:!1}static isAbortError(r,i=e.ErrorCode.ABORT){return n.isException(r)&&(r.name===t.AbortError||r.code===i)}toJSON(){return{Symbol:t.Exception,name:this.name,message:this.message,code:this.code,title:this.title,description:this.description,isCritical:this.isCritical,severity:this.severity,status:this.status,cause:this.cause}}static normalizeCause(e){return!n.isException(e)||e instanceof n?e:new n(e)}};exports.Exception=n,exports.ExceptionName=t;
package/dist/index.d.cts CHANGED
@@ -1,177 +1,2 @@
1
- import { ErrorCode } from "./code/index.cjs";
2
- //#region src/error-names.d.ts
3
- /**
4
- * Exception Name.
5
- *
6
- * [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/DOMException#error_names)
7
- */
8
- export declare const ExceptionName: {
9
- readonly Exception: "Exception";
10
- readonly AbortError: "AbortError";
11
- readonly NotAllowedError: "NotAllowedError";
12
- readonly NotFoundError: "NotFoundError";
13
- readonly NotSupportedError: "NotSupportedError";
14
- readonly InvalidStateError: "InvalidStateError";
15
- readonly InvalidAccessError: "InvalidAccessError";
16
- readonly NetworkError: "NetworkError";
17
- readonly SecurityError: "SecurityError";
18
- readonly TimeoutError: "TimeoutError";
19
- readonly QuotaExceededError: "QuotaExceededError";
20
- readonly DataError: "DataError";
21
- readonly EncodingError: "EncodingError";
22
- readonly OperationError: "OperationError";
23
- readonly ConstraintError: "ConstraintError";
24
- readonly TransactionInactiveError: "TransactionInactiveError";
25
- readonly ReadOnlyError: "ReadOnlyError";
26
- readonly VersionError: "VersionError";
27
- readonly NoModificationAllowedError: "NoModificationAllowedError";
28
- readonly HierarchyRequestError: "HierarchyRequestError";
29
- readonly WrongDocumentError: "WrongDocumentError";
30
- readonly InvalidCharacterError: "InvalidCharacterError";
31
- readonly NamespaceError: "NamespaceError";
32
- readonly SyntaxError: "SyntaxError";
33
- readonly DataCloneError: "DataCloneError";
34
- readonly URLMismatchError: "URLMismatchError";
35
- readonly InvalidModificationError: "InvalidModificationError";
36
- readonly NotReadableError: "NotReadableError";
37
- };
38
- export type ExceptionName = (typeof ExceptionName)[keyof typeof ExceptionName];
39
- //#endregion
40
- //#region src/index.d.ts
41
- /**
42
- * Interface representing the options for an Exception.
43
- *
44
- * @template T The type of the error code.
45
- *
46
- * @extends ErrorOptions
47
- */
48
- export interface ExceptionOptions<T = ErrorCode> extends ErrorOptions {
49
- /**
50
- * The error interface name.
51
- *
52
- * @see {@link ExceptionName} for a list of possible standard values.
53
- *
54
- * @default ExceptionName.Exception
55
- */
56
- name?: string;
57
- /**
58
- * The error message containing technical informations about the error.
59
- *
60
- * It shouldn't be rendered to the user.
61
- */
62
- message?: string;
63
- /**
64
- * The error title.
65
- *
66
- */
67
- title?: string;
68
- /**
69
- * The error description.
70
- *
71
- */
72
- description?: string;
73
- /**
74
- * The error code associated with the Exception.
75
- *
76
- */
77
- code: T;
78
- /**
79
- * Indicates whether the error is a critical error.
80
- *
81
- * @default false
82
- */
83
- isCritical?: boolean;
84
- /**
85
- * The HTTP status code associated with the Exception.
86
- *
87
- */
88
- status?: number;
89
- /**
90
- * The error cause.
91
- *
92
- */
93
- cause?: unknown;
94
- }
95
- /**
96
- * Exception Class.
97
- *
98
- * @template T The type of the code property of the Exception. Defaults to `ErrorCode`.
99
- *
100
- * @extends Error
101
- * @implements ExceptionOptions<T>
102
- */
103
- export declare class Exception<T = ErrorCode> extends Error {
104
- private readonly __typename;
105
- /**
106
- * The error interface name.
107
- *
108
- */
109
- readonly name: string;
110
- /**
111
- * The error message containing technical informations about the error.
112
- *
113
- * ⚠️ do not render `Exception.message` to the user.
114
- */
115
- readonly message: string;
116
- /**
117
- * The error title that can be rendered to the user.
118
- *
119
- */
120
- readonly title: string | undefined;
121
- /**
122
- * The error description that can be rendered to the user.
123
- *
124
- */
125
- readonly description: string | undefined;
126
- /**
127
- * The error code.
128
- *
129
- */
130
- readonly code: T;
131
- /**
132
- * Indicates whether the error is a critical error.
133
- *
134
- */
135
- readonly isCritical: boolean;
136
- /**
137
- * The HTTP status code associated with the Exception.
138
- *
139
- */
140
- readonly status: number | undefined;
141
- /**
142
- * The error cause.
143
- *
144
- */
145
- readonly cause: unknown;
146
- /**
147
- * Constructs a new Exception instance.
148
- *
149
- * @param options An object defining Exception options. See {@link ExceptionOptions} for more info.
150
- */
151
- constructor(options: ExceptionOptions<T>);
152
- /**
153
- * Determines if the provided error is an instance of the Exception class.
154
- *
155
- * @template T The type of the code property of the Exception.
156
- *
157
- * @param error The error to check.
158
- * @returns `true` if the error is an instance of Exception or has a `__typename` property equal to 'Exception', `false` otherwise.
159
- */
160
- static isException<T = ErrorCode>(error: any): error is Exception<T>;
161
- /**
162
- * Determines if the provided error is an instance of the Exception class and has the ABORT ErrorCode.
163
- *
164
- * @template T The type of the code property of the Exception.
165
- *
166
- * @param error The error to check.
167
- * @returns `true` if the error is an `Exception` and has the ABORT ErrorCode, `false` otherwise.
168
- */
169
- static isAbortError<T = ErrorCode>(error: any, code?: T): error is Exception<T>;
170
- /**
171
- * Converts the instance to a JSON object.
172
- *
173
- * @returns A JSON representation of the instance, including the message property.
174
- */
175
- toJSON(): this;
176
- }
177
- //#endregion
1
+ import { a as ExceptionName, i as Severity, n as ExceptionOptions, r as JSONException, t as Exception } from "./index-CAXMeOIU.cjs";
2
+ export { Exception, ExceptionName, ExceptionOptions, JSONException, Severity };
package/dist/index.d.mts CHANGED
@@ -1,177 +1,2 @@
1
- import { ErrorCode } from "./code/index.mjs";
2
- //#region src/error-names.d.ts
3
- /**
4
- * Exception Name.
5
- *
6
- * [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/DOMException#error_names)
7
- */
8
- export declare const ExceptionName: {
9
- readonly Exception: "Exception";
10
- readonly AbortError: "AbortError";
11
- readonly NotAllowedError: "NotAllowedError";
12
- readonly NotFoundError: "NotFoundError";
13
- readonly NotSupportedError: "NotSupportedError";
14
- readonly InvalidStateError: "InvalidStateError";
15
- readonly InvalidAccessError: "InvalidAccessError";
16
- readonly NetworkError: "NetworkError";
17
- readonly SecurityError: "SecurityError";
18
- readonly TimeoutError: "TimeoutError";
19
- readonly QuotaExceededError: "QuotaExceededError";
20
- readonly DataError: "DataError";
21
- readonly EncodingError: "EncodingError";
22
- readonly OperationError: "OperationError";
23
- readonly ConstraintError: "ConstraintError";
24
- readonly TransactionInactiveError: "TransactionInactiveError";
25
- readonly ReadOnlyError: "ReadOnlyError";
26
- readonly VersionError: "VersionError";
27
- readonly NoModificationAllowedError: "NoModificationAllowedError";
28
- readonly HierarchyRequestError: "HierarchyRequestError";
29
- readonly WrongDocumentError: "WrongDocumentError";
30
- readonly InvalidCharacterError: "InvalidCharacterError";
31
- readonly NamespaceError: "NamespaceError";
32
- readonly SyntaxError: "SyntaxError";
33
- readonly DataCloneError: "DataCloneError";
34
- readonly URLMismatchError: "URLMismatchError";
35
- readonly InvalidModificationError: "InvalidModificationError";
36
- readonly NotReadableError: "NotReadableError";
37
- };
38
- export type ExceptionName = (typeof ExceptionName)[keyof typeof ExceptionName];
39
- //#endregion
40
- //#region src/index.d.ts
41
- /**
42
- * Interface representing the options for an Exception.
43
- *
44
- * @template T The type of the error code.
45
- *
46
- * @extends ErrorOptions
47
- */
48
- export interface ExceptionOptions<T = ErrorCode> extends ErrorOptions {
49
- /**
50
- * The error interface name.
51
- *
52
- * @see {@link ExceptionName} for a list of possible standard values.
53
- *
54
- * @default ExceptionName.Exception
55
- */
56
- name?: string;
57
- /**
58
- * The error message containing technical informations about the error.
59
- *
60
- * It shouldn't be rendered to the user.
61
- */
62
- message?: string;
63
- /**
64
- * The error title.
65
- *
66
- */
67
- title?: string;
68
- /**
69
- * The error description.
70
- *
71
- */
72
- description?: string;
73
- /**
74
- * The error code associated with the Exception.
75
- *
76
- */
77
- code: T;
78
- /**
79
- * Indicates whether the error is a critical error.
80
- *
81
- * @default false
82
- */
83
- isCritical?: boolean;
84
- /**
85
- * The HTTP status code associated with the Exception.
86
- *
87
- */
88
- status?: number;
89
- /**
90
- * The error cause.
91
- *
92
- */
93
- cause?: unknown;
94
- }
95
- /**
96
- * Exception Class.
97
- *
98
- * @template T The type of the code property of the Exception. Defaults to `ErrorCode`.
99
- *
100
- * @extends Error
101
- * @implements ExceptionOptions<T>
102
- */
103
- export declare class Exception<T = ErrorCode> extends Error {
104
- private readonly __typename;
105
- /**
106
- * The error interface name.
107
- *
108
- */
109
- readonly name: string;
110
- /**
111
- * The error message containing technical informations about the error.
112
- *
113
- * ⚠️ do not render `Exception.message` to the user.
114
- */
115
- readonly message: string;
116
- /**
117
- * The error title that can be rendered to the user.
118
- *
119
- */
120
- readonly title: string | undefined;
121
- /**
122
- * The error description that can be rendered to the user.
123
- *
124
- */
125
- readonly description: string | undefined;
126
- /**
127
- * The error code.
128
- *
129
- */
130
- readonly code: T;
131
- /**
132
- * Indicates whether the error is a critical error.
133
- *
134
- */
135
- readonly isCritical: boolean;
136
- /**
137
- * The HTTP status code associated with the Exception.
138
- *
139
- */
140
- readonly status: number | undefined;
141
- /**
142
- * The error cause.
143
- *
144
- */
145
- readonly cause: unknown;
146
- /**
147
- * Constructs a new Exception instance.
148
- *
149
- * @param options An object defining Exception options. See {@link ExceptionOptions} for more info.
150
- */
151
- constructor(options: ExceptionOptions<T>);
152
- /**
153
- * Determines if the provided error is an instance of the Exception class.
154
- *
155
- * @template T The type of the code property of the Exception.
156
- *
157
- * @param error The error to check.
158
- * @returns `true` if the error is an instance of Exception or has a `__typename` property equal to 'Exception', `false` otherwise.
159
- */
160
- static isException<T = ErrorCode>(error: any): error is Exception<T>;
161
- /**
162
- * Determines if the provided error is an instance of the Exception class and has the ABORT ErrorCode.
163
- *
164
- * @template T The type of the code property of the Exception.
165
- *
166
- * @param error The error to check.
167
- * @returns `true` if the error is an `Exception` and has the ABORT ErrorCode, `false` otherwise.
168
- */
169
- static isAbortError<T = ErrorCode>(error: any, code?: T): error is Exception<T>;
170
- /**
171
- * Converts the instance to a JSON object.
172
- *
173
- * @returns A JSON representation of the instance, including the message property.
174
- */
175
- toJSON(): this;
176
- }
177
- //#endregion
1
+ import { a as ExceptionName, i as Severity, n as ExceptionOptions, r as JSONException, t as Exception } from "./index-D_kjKA8h.mjs";
2
+ export { Exception, ExceptionName, ExceptionOptions, JSONException, Severity };
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{ErrorCode as e}from"./code/index.mjs";const t={Exception:`Exception`,AbortError:`AbortError`,NotAllowedError:`NotAllowedError`,NotFoundError:`NotFoundError`,NotSupportedError:`NotSupportedError`,InvalidStateError:`InvalidStateError`,InvalidAccessError:`InvalidAccessError`,NetworkError:`NetworkError`,SecurityError:`SecurityError`,TimeoutError:`TimeoutError`,QuotaExceededError:`QuotaExceededError`,DataError:`DataError`,EncodingError:`EncodingError`,OperationError:`OperationError`,ConstraintError:`ConstraintError`,TransactionInactiveError:`TransactionInactiveError`,ReadOnlyError:`ReadOnlyError`,VersionError:`VersionError`,NoModificationAllowedError:`NoModificationAllowedError`,HierarchyRequestError:`HierarchyRequestError`,WrongDocumentError:`WrongDocumentError`,InvalidCharacterError:`InvalidCharacterError`,NamespaceError:`NamespaceError`,SyntaxError:`SyntaxError`,DataCloneError:`DataCloneError`,URLMismatchError:`URLMismatchError`,InvalidModificationError:`InvalidModificationError`,NotReadableError:`NotReadableError`};var n=class n extends Error{__typename=t.Exception;name=this.__typename;message;title;description;code;isCritical;status;cause;constructor(e){let{message:t=`Unknown error.`}=e;super(t),e.name&&(this.name=e.name),this.message=t,this.title=e.title,this.description=e.description,this.code=e.code,this.isCritical=e.isCritical??!1,this.status=e.status,this.cause=n.isException(e.cause)?new n(e.cause):e.cause}static isException(e){return e instanceof n||!!e&&typeof e==`object`&&`__typename`in e&&e.__typename===t.Exception}static isAbortError(r,i=e.ABORT){return n.isException(r)&&(r.name===t.AbortError||r.code===i)}toJSON(){return{...this,message:this.message,cause:this.cause}}};export{n as Exception,t as ExceptionName};
1
+ import{ErrorCode as e}from"./code/index.mjs";const t={Exception:`Exception`,AbortError:`AbortError`,NotAllowedError:`NotAllowedError`,NotFoundError:`NotFoundError`,NotSupportedError:`NotSupportedError`,InvalidStateError:`InvalidStateError`,InvalidAccessError:`InvalidAccessError`,NetworkError:`NetworkError`,SecurityError:`SecurityError`,TimeoutError:`TimeoutError`,QuotaExceededError:`QuotaExceededError`,DataError:`DataError`,EncodingError:`EncodingError`,OperationError:`OperationError`,ConstraintError:`ConstraintError`,TransactionInactiveError:`TransactionInactiveError`,ReadOnlyError:`ReadOnlyError`,VersionError:`VersionError`,NoModificationAllowedError:`NoModificationAllowedError`,HierarchyRequestError:`HierarchyRequestError`,WrongDocumentError:`WrongDocumentError`,InvalidCharacterError:`InvalidCharacterError`,NamespaceError:`NamespaceError`,SyntaxError:`SyntaxError`,DataCloneError:`DataCloneError`,URLMismatchError:`URLMismatchError`,InvalidModificationError:`InvalidModificationError`,NotReadableError:`NotReadableError`};var n=class n extends Error{static Symbol=Symbol.for(t.Exception);name=t.Exception;message;title;description;code;status;cause;severity;isCritical;static RECOVERABLE=1;static SEVERE=2;static CRITICAL=3;constructor(e){let{message:t=`Unknown error.`}=e;super(t),e.name&&(this.name=e.name);let{isCritical:r,severity:i=r?n.CRITICAL:void 0}=e;this.message=t,this.title=e.title,this.description=e.description,this.code=e.code,this.severity=i,this.isCritical=r??this.severity===n.CRITICAL,this.status=e.status,this.cause=n.normalizeCause(e.cause)}static isException(e){return!e||typeof e!=`object`?!1:e instanceof n?!0:`Symbol`in e?e.Symbol===n.Symbol||typeof e.Symbol==`string`&&Symbol.for(e.Symbol)===n.Symbol:!1}static isAbortError(r,i=e.ABORT){return n.isException(r)&&(r.name===t.AbortError||r.code===i)}toJSON(){return{Symbol:t.Exception,name:this.name,message:this.message,code:this.code,title:this.title,description:this.description,isCritical:this.isCritical,severity:this.severity,status:this.status,cause:this.cause}}static normalizeCause(e){return!n.isException(e)||e instanceof n?e:new n(e)}};export{n as Exception,t as ExceptionName};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alessiofrittoli/exception",
3
- "version": "4.1.1",
3
+ "version": "4.3.0",
4
4
  "description": "Handle errors with ease",
5
5
  "type": "module",
6
6
  "author": {
@@ -62,26 +62,27 @@
62
62
  },
63
63
  "sideEffects": false,
64
64
  "devDependencies": {
65
- "@alessiofrittoli/node-scripts": "^4.0.0-alpha.3",
66
- "@alessiofrittoli/package-configs": "^1.6.0",
65
+ "@alessiofrittoli/node-scripts": "^4.2.0",
66
+ "@alessiofrittoli/package-configs": "^1.12.0",
67
+ "@alessiofrittoli/type-utils": "^2.2.0",
67
68
  "@types/node": "^24.19.1",
68
- "@vitest/coverage-v8": "^5.0.3",
69
- "concurrently": "^9.2.1",
69
+ "@vitest/coverage-v8": "^5.1.0",
70
+ "concurrently": "^10.0.6",
70
71
  "http-server": "^14.1.1",
71
- "oxlint": "^1.86.0",
72
- "prettier": "^3.9.9",
72
+ "oxlint": "^1.90.0",
73
+ "oxlint-tsgolint": "^7.0.2005",
74
+ "prettier": "^3.9.10",
73
75
  "prettier-plugin-sort-imports": "^1.8.11",
74
- "tsdown": "^0.23.0",
76
+ "tsdown": "^0.23.4",
75
77
  "typescript": "^6.0.3",
76
- "vite": "^8.3.2",
77
- "vitest": "^5.0.3"
78
+ "vitest": "^5.1.0"
78
79
  },
79
80
  "scripts": {
80
81
  "//1a": "*********************************************************************",
81
82
  "//1b": "******************** DEV - BUILD - LINT - RELEASE *******************",
82
83
  "//1c": "*********************************************************************",
83
84
  "dev": "tsdown --watch",
84
- "build": "pnpm lint && pnpm tsc && pnpm tsdown",
85
+ "build": "pnpm lint && pnpm tsdown",
85
86
  "lint": "oxlint --report-unused-disable-directives --max-warnings 0",
86
87
  "release": "node scripts/release.ts --verbose --npm",
87
88
  "//2a": "*********************************************************************",