@alessiofrittoli/exception 3.0.0 → 3.2.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.
- package/README.md +61 -20
- package/dist/abort.d.mts +4 -4
- package/dist/abort.d.ts +4 -4
- package/dist/abort.js +32 -2
- package/dist/abort.mjs +32 -2
- package/dist/chunk-HGZVEYNW.mjs +59 -0
- package/dist/chunk-JG4AGGUJ.js +59 -0
- package/dist/chunk-KMJW7KZM.js +18 -0
- package/dist/chunk-M2EF7GYS.mjs +18 -0
- package/dist/code.d.mts +5 -1
- package/dist/code.d.ts +5 -1
- package/dist/code.js +6 -2
- package/dist/code.mjs +6 -2
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +7 -2
- package/dist/index.mjs +7 -2
- package/package.json +8 -7
- package/dist/abort.js.map +0 -1
- package/dist/abort.mjs.map +0 -1
- package/dist/chunk-CLZRQMJF.mjs +0 -2
- package/dist/chunk-CLZRQMJF.mjs.map +0 -1
- package/dist/chunk-FXYDTIUG.js +0 -2
- package/dist/chunk-FXYDTIUG.js.map +0 -1
- package/dist/chunk-JM2G32JS.mjs +0 -2
- package/dist/chunk-JM2G32JS.mjs.map +0 -1
- package/dist/chunk-OJYXDMWZ.js +0 -2
- package/dist/chunk-OJYXDMWZ.js.map +0 -1
- package/dist/code.js.map +0 -1
- package/dist/code.mjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/index.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -28,7 +28,9 @@ This documentation describes the `Exception` class, which provides a structured
|
|
|
28
28
|
- [ExceptionOptions Interface](#exceptionoptions-interface)
|
|
29
29
|
- [Exception Class](#exception-class)
|
|
30
30
|
- [AbortError Class](#aborterror-class)
|
|
31
|
-
|
|
31
|
+
- [AbortError Usage Scenarios](#aborterror-usage-scenarios)
|
|
32
|
+
- [`ErrorCode` enum](#errorcode-enum)
|
|
33
|
+
- [Examples](#examples)
|
|
32
34
|
- [Development](#development)
|
|
33
35
|
- [Install depenendencies](#install-depenendencies)
|
|
34
36
|
- [Build the source code](#build-the-source-code)
|
|
@@ -156,13 +158,13 @@ The constructor initializes an `AbortError` instance with a custom message and o
|
|
|
156
158
|
| Parameter | Type | Description |
|
|
157
159
|
|-----------|--------------------|-----------------------------------------------------------------|
|
|
158
160
|
| `message` | `TMessage` | (Required) The error message. Can be a string or a custom type. |
|
|
159
|
-
| `options` | `AbortErrorOptions`| (Optional) An object containing the error options. It extends the [`ExceptionOptions` Interface](#exceptionoptions-interface) and omit
|
|
161
|
+
| `options` | `AbortErrorOptions`| (Optional) An object containing the error options. It extends the [`ExceptionOptions` Interface](#exceptionoptions-interface) and omit the `name` property. The `code` defaults to `ErrorCode.ABORT` but can be optionally customized. |
|
|
160
162
|
|
|
161
163
|
---
|
|
162
164
|
|
|
163
|
-
|
|
165
|
+
##### AbortError Usage Scenarios
|
|
164
166
|
|
|
165
|
-
|
|
167
|
+
###### Precise Abort Errors Handling
|
|
166
168
|
|
|
167
169
|
```ts
|
|
168
170
|
import { AbortError } from '@alessiofrittoli/exception/abort'
|
|
@@ -194,6 +196,45 @@ try {
|
|
|
194
196
|
|
|
195
197
|
---
|
|
196
198
|
|
|
199
|
+
###### Using custom Abort Error codes
|
|
200
|
+
|
|
201
|
+
```ts
|
|
202
|
+
import { AbortError } from '@alessiofrittoli/exception/abort'
|
|
203
|
+
|
|
204
|
+
enum CustomAbortCode
|
|
205
|
+
{
|
|
206
|
+
CUSTOM_CODE = 'ERR:CUSTOM_ABORT_CODE',
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
try {
|
|
210
|
+
const controller = new AbortController()
|
|
211
|
+
const { signal } = controller
|
|
212
|
+
|
|
213
|
+
button.addEventListener( 'click', () => {
|
|
214
|
+
controller.abort(
|
|
215
|
+
new AbortError( 'User cancelled the request.', { code: CustomAbortCode.CUSTOM_CODE } )
|
|
216
|
+
)
|
|
217
|
+
} )
|
|
218
|
+
|
|
219
|
+
await fetch( ..., { signal } )
|
|
220
|
+
} catch ( error ) {
|
|
221
|
+
|
|
222
|
+
if ( AbortError.isException( error ) ) {
|
|
223
|
+
if ( AbortError.isAbortError( error, CustomAbortCode.CUSTOM_CODE ) ) {
|
|
224
|
+
// handle abort error
|
|
225
|
+
console.log( error.code ) // `error.code` is type of `CustomAbortCode.CUSTOM_CODE`.
|
|
226
|
+
return
|
|
227
|
+
}
|
|
228
|
+
// handle other Exception errors
|
|
229
|
+
return
|
|
230
|
+
}
|
|
231
|
+
// handle other unknown errors
|
|
232
|
+
|
|
233
|
+
}
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
---
|
|
237
|
+
|
|
197
238
|
#### `ErrorCode` enum
|
|
198
239
|
|
|
199
240
|
The `ErrorCode` enum is a utility that provides pre-defined constants for the most common error codes.\
|
|
@@ -203,14 +244,18 @@ It is designed to simplify error handling and improve feedback quality returned
|
|
|
203
244
|
|
|
204
245
|
<summary>Constants Overview</summary>
|
|
205
246
|
|
|
206
|
-
| Constant
|
|
207
|
-
|
|
208
|
-
| `UNKNOWN`
|
|
209
|
-
| `ABORT`
|
|
210
|
-
| `EMPTY_VALUE`
|
|
211
|
-
| `WRONG_VALUE`
|
|
212
|
-
| `EXPIRED`
|
|
213
|
-
| `TOO_EARLY`
|
|
247
|
+
| Constant | Value | Description |
|
|
248
|
+
|-----------------|--------------------|---------------------------------------------------------|
|
|
249
|
+
| `UNKNOWN` | `ERR:UNKNOWN` | Returned when an unexpected error occured. |
|
|
250
|
+
| `ABORT` | `ERR:ABORT` | Returned when user abort the request. |
|
|
251
|
+
| `EMPTY_VALUE` | `ERR:EMPTYVALUE` | Returned when a required value is "falsy". |
|
|
252
|
+
| `WRONG_VALUE` | `ERR:WRONGVALUE` | Return when a required value is not the expected value. |
|
|
253
|
+
| `EXPIRED` | `ERR:EXPIRED` | Returned when a requested has been performed too late. |
|
|
254
|
+
| `TOO_EARLY` | `ERR:TOOEARLY` | Returned when a request has been performed too early. |
|
|
255
|
+
| `TOO_MANY` | `ERR:TOOMANY` | Could be return in combination with a 429 Too Many Requests Response Status. |
|
|
256
|
+
| `QUOTA_REACHED` | `ERR:QUOTAREACHED` | Returned when a specific quota has been reached. |
|
|
257
|
+
| `NOT_FOUND` | `ERR:NOTFOUND` | Returned when a resource cannot be found. |
|
|
258
|
+
| `OFFLINE` | `ERR:INTERNETDISCONNECTED` | Could be used to throw errors when user is offline. |
|
|
214
259
|
|
|
215
260
|
</details>
|
|
216
261
|
|
|
@@ -246,11 +291,9 @@ export default ErrorCode
|
|
|
246
291
|
|
|
247
292
|
---
|
|
248
293
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
<summary>Usage</summary>
|
|
294
|
+
#### Examples
|
|
252
295
|
|
|
253
|
-
|
|
296
|
+
##### Using the default `ErrorCode` to throw a new `Exception`
|
|
254
297
|
|
|
255
298
|
```ts
|
|
256
299
|
import { Exception } from '@alessiofrittoli/exception'
|
|
@@ -262,7 +305,7 @@ throw new Exception( 'Password is a required field to log you in.', {
|
|
|
262
305
|
} )
|
|
263
306
|
```
|
|
264
307
|
|
|
265
|
-
|
|
308
|
+
##### Using custom `ErrorCode` to throw a new `Exception`
|
|
266
309
|
|
|
267
310
|
```ts
|
|
268
311
|
import { Exception } from '@alessiofrittoli/exception'
|
|
@@ -274,7 +317,7 @@ throw new Exception( 'Invalid signature.', {
|
|
|
274
317
|
} )
|
|
275
318
|
```
|
|
276
319
|
|
|
277
|
-
|
|
320
|
+
##### Using `ErrorCode` to handle errors
|
|
278
321
|
|
|
279
322
|
```ts
|
|
280
323
|
import { ErrorCode } from '@/error-code' // previously created in `myproject/src/error-code.ts`
|
|
@@ -295,8 +338,6 @@ try {
|
|
|
295
338
|
}
|
|
296
339
|
```
|
|
297
340
|
|
|
298
|
-
</details>
|
|
299
|
-
|
|
300
341
|
---
|
|
301
342
|
|
|
302
343
|
### Development
|
package/dist/abort.d.mts
CHANGED
|
@@ -6,7 +6,7 @@ import { ErrorCode } from './code.mjs';
|
|
|
6
6
|
*
|
|
7
7
|
* @extends ExceptionOptions
|
|
8
8
|
*/
|
|
9
|
-
interface AbortErrorOptions extends Omit<ExceptionOptions
|
|
9
|
+
interface AbortErrorOptions<TCode = ErrorCode> extends Partial<Omit<ExceptionOptions<TCode>, 'name'>> {
|
|
10
10
|
/** The HTTP status code associated with the Exception. */
|
|
11
11
|
status?: number;
|
|
12
12
|
}
|
|
@@ -17,8 +17,8 @@ interface AbortErrorOptions extends Omit<ExceptionOptions, 'code' | 'name'> {
|
|
|
17
17
|
*
|
|
18
18
|
* @extends Exception
|
|
19
19
|
*/
|
|
20
|
-
declare class AbortError<TMessage> extends Exception<TMessage,
|
|
21
|
-
constructor(reason: TMessage, options?: AbortErrorOptions);
|
|
20
|
+
declare class AbortError<TMessage = string, TCode = ErrorCode> extends Exception<TMessage, TCode> implements AbortErrorOptions<TCode> {
|
|
21
|
+
constructor(reason: TMessage, options?: AbortErrorOptions<TCode>);
|
|
22
22
|
/**
|
|
23
23
|
* Determines if the provided error is an instance of the AbortError class and has the ABORT ErrorCode.
|
|
24
24
|
*
|
|
@@ -29,7 +29,7 @@ declare class AbortError<TMessage> extends Exception<TMessage, ErrorCode.ABORT>
|
|
|
29
29
|
* @param error The error to check.
|
|
30
30
|
* @returns `true` if the error is an `AbortError` and has the ABORT ErrorCode, `false` otherwise.
|
|
31
31
|
*/
|
|
32
|
-
static isAbortError<TMessage = string>(error: any): error is AbortError<TMessage>;
|
|
32
|
+
static isAbortError<TMessage = string, TCode = ErrorCode>(error: any, code?: TCode): error is AbortError<TMessage, TCode>;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
export { AbortError, type AbortErrorOptions };
|
package/dist/abort.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { ErrorCode } from './code.js';
|
|
|
6
6
|
*
|
|
7
7
|
* @extends ExceptionOptions
|
|
8
8
|
*/
|
|
9
|
-
interface AbortErrorOptions extends Omit<ExceptionOptions
|
|
9
|
+
interface AbortErrorOptions<TCode = ErrorCode> extends Partial<Omit<ExceptionOptions<TCode>, 'name'>> {
|
|
10
10
|
/** The HTTP status code associated with the Exception. */
|
|
11
11
|
status?: number;
|
|
12
12
|
}
|
|
@@ -17,8 +17,8 @@ interface AbortErrorOptions extends Omit<ExceptionOptions, 'code' | 'name'> {
|
|
|
17
17
|
*
|
|
18
18
|
* @extends Exception
|
|
19
19
|
*/
|
|
20
|
-
declare class AbortError<TMessage> extends Exception<TMessage,
|
|
21
|
-
constructor(reason: TMessage, options?: AbortErrorOptions);
|
|
20
|
+
declare class AbortError<TMessage = string, TCode = ErrorCode> extends Exception<TMessage, TCode> implements AbortErrorOptions<TCode> {
|
|
21
|
+
constructor(reason: TMessage, options?: AbortErrorOptions<TCode>);
|
|
22
22
|
/**
|
|
23
23
|
* Determines if the provided error is an instance of the AbortError class and has the ABORT ErrorCode.
|
|
24
24
|
*
|
|
@@ -29,7 +29,7 @@ declare class AbortError<TMessage> extends Exception<TMessage, ErrorCode.ABORT>
|
|
|
29
29
|
* @param error The error to check.
|
|
30
30
|
* @returns `true` if the error is an `AbortError` and has the ABORT ErrorCode, `false` otherwise.
|
|
31
31
|
*/
|
|
32
|
-
static isAbortError<TMessage = string>(error: any): error is AbortError<TMessage>;
|
|
32
|
+
static isAbortError<TMessage = string, TCode = ErrorCode>(error: any, code?: TCode): error is AbortError<TMessage, TCode>;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
export { AbortError, type AbortErrorOptions };
|
package/dist/abort.js
CHANGED
|
@@ -1,2 +1,32 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
-
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunkJG4AGGUJjs = require('./chunk-JG4AGGUJ.js');
|
|
4
|
+
require('./chunk-KMJW7KZM.js');
|
|
5
|
+
|
|
6
|
+
// src/abort.ts
|
|
7
|
+
var AbortError = class extends _chunkJG4AGGUJjs.Exception {
|
|
8
|
+
constructor(reason, options = {}) {
|
|
9
|
+
const name = "AbortError";
|
|
10
|
+
const {
|
|
11
|
+
code = "ERR:ABORT" /* ABORT */,
|
|
12
|
+
...rest
|
|
13
|
+
} = options;
|
|
14
|
+
super(reason, { ...rest, name, code });
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Determines if the provided error is an instance of the AbortError class and has the ABORT ErrorCode.
|
|
18
|
+
*
|
|
19
|
+
* This won't work for `new DOMException( 'Abort reason', 'AbortError' )` since we type guard the checked value to `AbortError<TMessage>`.
|
|
20
|
+
*
|
|
21
|
+
* @template TMessage The type of the message property of the AbortError.
|
|
22
|
+
*
|
|
23
|
+
* @param error The error to check.
|
|
24
|
+
* @returns `true` if the error is an `AbortError` and has the ABORT ErrorCode, `false` otherwise.
|
|
25
|
+
*/
|
|
26
|
+
static isAbortError(error, code) {
|
|
27
|
+
return super.isAbortError(error, code);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
exports.AbortError = AbortError;
|
package/dist/abort.mjs
CHANGED
|
@@ -1,2 +1,32 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
Exception
|
|
3
|
+
} from "./chunk-HGZVEYNW.mjs";
|
|
4
|
+
import "./chunk-M2EF7GYS.mjs";
|
|
5
|
+
|
|
6
|
+
// src/abort.ts
|
|
7
|
+
var AbortError = class extends Exception {
|
|
8
|
+
constructor(reason, options = {}) {
|
|
9
|
+
const name = "AbortError";
|
|
10
|
+
const {
|
|
11
|
+
code = "ERR:ABORT" /* ABORT */,
|
|
12
|
+
...rest
|
|
13
|
+
} = options;
|
|
14
|
+
super(reason, { ...rest, name, code });
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Determines if the provided error is an instance of the AbortError class and has the ABORT ErrorCode.
|
|
18
|
+
*
|
|
19
|
+
* This won't work for `new DOMException( 'Abort reason', 'AbortError' )` since we type guard the checked value to `AbortError<TMessage>`.
|
|
20
|
+
*
|
|
21
|
+
* @template TMessage The type of the message property of the AbortError.
|
|
22
|
+
*
|
|
23
|
+
* @param error The error to check.
|
|
24
|
+
* @returns `true` if the error is an `AbortError` and has the ABORT ErrorCode, `false` otherwise.
|
|
25
|
+
*/
|
|
26
|
+
static isAbortError(error, code) {
|
|
27
|
+
return super.isAbortError(error, code);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
export {
|
|
31
|
+
AbortError
|
|
32
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
var Exception = class _Exception extends Error {
|
|
3
|
+
/**
|
|
4
|
+
* Constructs a new Exception instance.
|
|
5
|
+
*
|
|
6
|
+
* @param message The message describing the exception.
|
|
7
|
+
* @param options Additional options for the exception.
|
|
8
|
+
*/
|
|
9
|
+
constructor(message, options) {
|
|
10
|
+
super("", options);
|
|
11
|
+
this.__typename = "Exception";
|
|
12
|
+
this.name = options.name || this.__typename;
|
|
13
|
+
this.message = message;
|
|
14
|
+
this.code = options.code;
|
|
15
|
+
this.status = options.status;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Determines if the provided error is an instance of the Exception class.
|
|
19
|
+
*
|
|
20
|
+
* @template TMessage The type of the message property of the Exception.
|
|
21
|
+
* @template TCode The type of the code property of the Exception.
|
|
22
|
+
*
|
|
23
|
+
* @param error The error to check.
|
|
24
|
+
* @returns `true` if the error is an instance of Exception or has a `__typename` property equal to 'Exception', `false` otherwise.
|
|
25
|
+
*/
|
|
26
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
27
|
+
static isException(error) {
|
|
28
|
+
return error instanceof _Exception || typeof error === "object" && "__typename" in error && error.__typename === "Exception";
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Determines if the provided error is an instance of the Exception class and has the ABORT ErrorCode.
|
|
32
|
+
*
|
|
33
|
+
* This won't work for `new DOMException( 'Abort reason', 'AbortError' )` since we type guard the checked value to `Exception<TMessage, ErrorCode.ABORT>`.
|
|
34
|
+
*
|
|
35
|
+
* @template TMessage The type of the message property of the Exception.
|
|
36
|
+
*
|
|
37
|
+
* @param error The error to check.
|
|
38
|
+
* @returns `true` if the error is an `Exception` and has the ABORT ErrorCode, `false` otherwise.
|
|
39
|
+
*/
|
|
40
|
+
static isAbortError(error, code = "ERR:ABORT" /* ABORT */) {
|
|
41
|
+
return _Exception.isException(error) && (error.name === "AbortError" || error.code === code);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Converts the instance to a JSON object.
|
|
45
|
+
*
|
|
46
|
+
* @returns A JSON representation of the instance, including the message property.
|
|
47
|
+
*/
|
|
48
|
+
toJSON() {
|
|
49
|
+
return {
|
|
50
|
+
...this,
|
|
51
|
+
message: this.message,
|
|
52
|
+
cause: this.cause
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export {
|
|
58
|
+
Exception
|
|
59
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/index.ts
|
|
2
|
+
var Exception = class _Exception extends Error {
|
|
3
|
+
/**
|
|
4
|
+
* Constructs a new Exception instance.
|
|
5
|
+
*
|
|
6
|
+
* @param message The message describing the exception.
|
|
7
|
+
* @param options Additional options for the exception.
|
|
8
|
+
*/
|
|
9
|
+
constructor(message, options) {
|
|
10
|
+
super("", options);
|
|
11
|
+
this.__typename = "Exception";
|
|
12
|
+
this.name = options.name || this.__typename;
|
|
13
|
+
this.message = message;
|
|
14
|
+
this.code = options.code;
|
|
15
|
+
this.status = options.status;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Determines if the provided error is an instance of the Exception class.
|
|
19
|
+
*
|
|
20
|
+
* @template TMessage The type of the message property of the Exception.
|
|
21
|
+
* @template TCode The type of the code property of the Exception.
|
|
22
|
+
*
|
|
23
|
+
* @param error The error to check.
|
|
24
|
+
* @returns `true` if the error is an instance of Exception or has a `__typename` property equal to 'Exception', `false` otherwise.
|
|
25
|
+
*/
|
|
26
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
27
|
+
static isException(error) {
|
|
28
|
+
return error instanceof _Exception || typeof error === "object" && "__typename" in error && error.__typename === "Exception";
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Determines if the provided error is an instance of the Exception class and has the ABORT ErrorCode.
|
|
32
|
+
*
|
|
33
|
+
* This won't work for `new DOMException( 'Abort reason', 'AbortError' )` since we type guard the checked value to `Exception<TMessage, ErrorCode.ABORT>`.
|
|
34
|
+
*
|
|
35
|
+
* @template TMessage The type of the message property of the Exception.
|
|
36
|
+
*
|
|
37
|
+
* @param error The error to check.
|
|
38
|
+
* @returns `true` if the error is an `Exception` and has the ABORT ErrorCode, `false` otherwise.
|
|
39
|
+
*/
|
|
40
|
+
static isAbortError(error, code = "ERR:ABORT" /* ABORT */) {
|
|
41
|
+
return _Exception.isException(error) && (error.name === "AbortError" || error.code === code);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Converts the instance to a JSON object.
|
|
45
|
+
*
|
|
46
|
+
* @returns A JSON representation of the instance, including the message property.
|
|
47
|
+
*/
|
|
48
|
+
toJSON() {
|
|
49
|
+
return {
|
|
50
|
+
...this,
|
|
51
|
+
message: this.message,
|
|
52
|
+
cause: this.cause
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
exports.Exception = Exception;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/code.ts
|
|
2
|
+
var ErrorCode = /* @__PURE__ */ ((ErrorCode2) => {
|
|
3
|
+
ErrorCode2["UNKNOWN"] = "ERR:UNKNOWN";
|
|
4
|
+
ErrorCode2["ABORT"] = "ERR:ABORT";
|
|
5
|
+
ErrorCode2["EMPTY_VALUE"] = "ERR:EMPTYVALUE";
|
|
6
|
+
ErrorCode2["WRONG_VALUE"] = "ERR:WRONGVALUE";
|
|
7
|
+
ErrorCode2["EXPIRED"] = "ERR:EXPIRED";
|
|
8
|
+
ErrorCode2["TOO_EARLY"] = "ERR:TOOEARLY";
|
|
9
|
+
ErrorCode2["TOO_MANY"] = "ERR:TOOMANY";
|
|
10
|
+
ErrorCode2["QUOTA_REACHED"] = "ERR:QUOTAREACHED";
|
|
11
|
+
ErrorCode2["NOT_FOUND"] = "ERR:NOTFOUND";
|
|
12
|
+
ErrorCode2["OFFLINE"] = "ERR:INTERNETDISCONNECTED";
|
|
13
|
+
return ErrorCode2;
|
|
14
|
+
})(ErrorCode || {});
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
exports.ErrorCode = ErrorCode;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// src/code.ts
|
|
2
|
+
var ErrorCode = /* @__PURE__ */ ((ErrorCode2) => {
|
|
3
|
+
ErrorCode2["UNKNOWN"] = "ERR:UNKNOWN";
|
|
4
|
+
ErrorCode2["ABORT"] = "ERR:ABORT";
|
|
5
|
+
ErrorCode2["EMPTY_VALUE"] = "ERR:EMPTYVALUE";
|
|
6
|
+
ErrorCode2["WRONG_VALUE"] = "ERR:WRONGVALUE";
|
|
7
|
+
ErrorCode2["EXPIRED"] = "ERR:EXPIRED";
|
|
8
|
+
ErrorCode2["TOO_EARLY"] = "ERR:TOOEARLY";
|
|
9
|
+
ErrorCode2["TOO_MANY"] = "ERR:TOOMANY";
|
|
10
|
+
ErrorCode2["QUOTA_REACHED"] = "ERR:QUOTAREACHED";
|
|
11
|
+
ErrorCode2["NOT_FOUND"] = "ERR:NOTFOUND";
|
|
12
|
+
ErrorCode2["OFFLINE"] = "ERR:INTERNETDISCONNECTED";
|
|
13
|
+
return ErrorCode2;
|
|
14
|
+
})(ErrorCode || {});
|
|
15
|
+
|
|
16
|
+
export {
|
|
17
|
+
ErrorCode
|
|
18
|
+
};
|
package/dist/code.d.mts
CHANGED
|
@@ -8,7 +8,11 @@ declare enum ErrorCode {
|
|
|
8
8
|
EMPTY_VALUE = "ERR:EMPTYVALUE",
|
|
9
9
|
WRONG_VALUE = "ERR:WRONGVALUE",
|
|
10
10
|
EXPIRED = "ERR:EXPIRED",
|
|
11
|
-
TOO_EARLY = "ERR:TOOEARLY"
|
|
11
|
+
TOO_EARLY = "ERR:TOOEARLY",
|
|
12
|
+
TOO_MANY = "ERR:TOOMANY",
|
|
13
|
+
QUOTA_REACHED = "ERR:QUOTAREACHED",
|
|
14
|
+
NOT_FOUND = "ERR:NOTFOUND",
|
|
15
|
+
OFFLINE = "ERR:INTERNETDISCONNECTED"
|
|
12
16
|
}
|
|
13
17
|
|
|
14
18
|
export { ErrorCode };
|
package/dist/code.d.ts
CHANGED
|
@@ -8,7 +8,11 @@ declare enum ErrorCode {
|
|
|
8
8
|
EMPTY_VALUE = "ERR:EMPTYVALUE",
|
|
9
9
|
WRONG_VALUE = "ERR:WRONGVALUE",
|
|
10
10
|
EXPIRED = "ERR:EXPIRED",
|
|
11
|
-
TOO_EARLY = "ERR:TOOEARLY"
|
|
11
|
+
TOO_EARLY = "ERR:TOOEARLY",
|
|
12
|
+
TOO_MANY = "ERR:TOOMANY",
|
|
13
|
+
QUOTA_REACHED = "ERR:QUOTAREACHED",
|
|
14
|
+
NOT_FOUND = "ERR:NOTFOUND",
|
|
15
|
+
OFFLINE = "ERR:INTERNETDISCONNECTED"
|
|
12
16
|
}
|
|
13
17
|
|
|
14
18
|
export { ErrorCode };
|
package/dist/code.js
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
-
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunkKMJW7KZMjs = require('./chunk-KMJW7KZM.js');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
exports.ErrorCode = _chunkKMJW7KZMjs.ErrorCode;
|
package/dist/code.mjs
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -56,7 +56,7 @@ declare class Exception<TMessage = string, TCode = ErrorCode> extends Error impl
|
|
|
56
56
|
* @param error The error to check.
|
|
57
57
|
* @returns `true` if the error is an `Exception` and has the ABORT ErrorCode, `false` otherwise.
|
|
58
58
|
*/
|
|
59
|
-
static isAbortError<TMessage = string>(error: any): error is Exception<TMessage,
|
|
59
|
+
static isAbortError<TMessage = string, TCode = ErrorCode>(error: any, code?: TCode): error is Exception<TMessage, TCode>;
|
|
60
60
|
/**
|
|
61
61
|
* Converts the instance to a JSON object.
|
|
62
62
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -56,7 +56,7 @@ declare class Exception<TMessage = string, TCode = ErrorCode> extends Error impl
|
|
|
56
56
|
* @param error The error to check.
|
|
57
57
|
* @returns `true` if the error is an `Exception` and has the ABORT ErrorCode, `false` otherwise.
|
|
58
58
|
*/
|
|
59
|
-
static isAbortError<TMessage = string>(error: any): error is Exception<TMessage,
|
|
59
|
+
static isAbortError<TMessage = string, TCode = ErrorCode>(error: any, code?: TCode): error is Exception<TMessage, TCode>;
|
|
60
60
|
/**
|
|
61
61
|
* Converts the instance to a JSON object.
|
|
62
62
|
*
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,7 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
-
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunkJG4AGGUJjs = require('./chunk-JG4AGGUJ.js');
|
|
4
|
+
require('./chunk-KMJW7KZM.js');
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
exports.Exception = _chunkJG4AGGUJjs.Exception;
|
package/dist/index.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alessiofrittoli/exception",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"description": "Handle errors with ease",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Alessio Frittoli",
|
|
@@ -53,10 +53,11 @@
|
|
|
53
53
|
"sideEffects": false,
|
|
54
54
|
"scripts": {
|
|
55
55
|
"//1a": "*********************************************************************",
|
|
56
|
-
"//1b": "
|
|
56
|
+
"//1b": "******************** DEV - BUILD - LINT - RELEASE *******************",
|
|
57
57
|
"//1c": "*********************************************************************",
|
|
58
|
-
"
|
|
59
|
-
"build:
|
|
58
|
+
"dev": "NODE_ENV=development tsup --watch",
|
|
59
|
+
"build:prod": "NODE_ENV=production tsup",
|
|
60
|
+
"build": "pnpm lint && pnpm test:ci && pnpm build:prod",
|
|
60
61
|
"lint": "eslint",
|
|
61
62
|
"release": "node scripts/publish.js --verbose --npm",
|
|
62
63
|
"//2a": "*********************************************************************",
|
|
@@ -74,11 +75,11 @@
|
|
|
74
75
|
"test:coverage:serve": "concurrently --prefix none --kill-others \"pnpm test:coverage\" \"pnpm test:serve-coverage\""
|
|
75
76
|
},
|
|
76
77
|
"devDependencies": {
|
|
77
|
-
"@alessiofrittoli/node-scripts": "^2.
|
|
78
|
+
"@alessiofrittoli/node-scripts": "^2.5.0",
|
|
78
79
|
"@eslint/js": "^9.25.1",
|
|
79
80
|
"@jest/globals": "^29.7.0",
|
|
80
81
|
"@types/jest": "^29.5.14",
|
|
81
|
-
"@types/node": "^22.15.
|
|
82
|
+
"@types/node": "^22.15.3",
|
|
82
83
|
"concurrently": "^9.1.2",
|
|
83
84
|
"dotenv": "^16.5.0",
|
|
84
85
|
"esbuild": "0.25.3",
|
|
@@ -90,7 +91,7 @@
|
|
|
90
91
|
"ts-node": "^10.9.2",
|
|
91
92
|
"tsup": "^8.4.0",
|
|
92
93
|
"typescript": "^5.8.3",
|
|
93
|
-
"typescript-eslint": "^8.31.
|
|
94
|
+
"typescript-eslint": "^8.31.1"
|
|
94
95
|
},
|
|
95
96
|
"pnpm": {
|
|
96
97
|
"onlyBuiltDependencies": [
|
package/dist/abort.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/alessio/Documents/Personal/projects/exception/dist/abort.js","../src/abort.ts"],"names":["AbortError","Exception","reason","options","error"],"mappings":"AAAA,+HAAuC,+BAA4B,ICsBtDA,CAAAA,CAAN,MAAA,QAAmCC,kBAC1C,CACC,WAAA,CAAaC,CAAAA,CAAkBC,CAAAA,CAC/B,CACC,KAAA,CAAOD,CAAAA,CAAQ,CAAE,IAAA,CAAM,YAAA,CAAc,IAAA,CAAA,WAAA,CAAuB,GAAGC,CAAQ,CAAE,CAC1E,CAcA,OAAO,YAAA,CAAiCC,CAAAA,CACxC,CACC,OAAO,KAAA,CAAM,YAAA,CAAcA,CAAM,CAClC,CACD,CAAA,CAAA,uBAAA","file":"/Users/alessio/Documents/Personal/projects/exception/dist/abort.js","sourcesContent":[null,"import { Exception, ExceptionOptions } from '.'\nimport { ErrorCode } from './code'\n\n/**\n * Interface representing the options for an Exception.\n *\n * @extends ExceptionOptions\n */\nexport interface AbortErrorOptions extends Omit<ExceptionOptions, 'code' | 'name'>\n{\n\t/** The HTTP status code associated with the Exception. */\n\tstatus?: number\n}\n\n\n/**\n * Exception Class.\n * \n * @template TMessage The type of the message property of the Exception. Defaults to `string`.\n *\n * @extends Exception\n */\nexport class AbortError<TMessage> extends Exception<TMessage, ErrorCode.ABORT> implements AbortErrorOptions\n{\n\tconstructor( reason: TMessage, options?: AbortErrorOptions )\n\t{\n\t\tsuper( reason, { name: 'AbortError', code: ErrorCode.ABORT, ...options } )\n\t}\n\n\n\t/**\n\t * Determines if the provided error is an instance of the AbortError class and has the ABORT ErrorCode.\n\t * \n\t * This won't work for `new DOMException( 'Abort reason', 'AbortError' )` since we type guard the checked value to `AbortError<TMessage>`.\n\t *\n\t * @template TMessage The type of the message property of the AbortError.\n\t * \n\t * @param\terror The error to check.\n\t * @returns\t`true` if the error is an `AbortError` and has the ABORT ErrorCode, `false` otherwise.\n\t */\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tstatic isAbortError<TMessage = string>( error: any ): error is AbortError<TMessage>\n\t{\n\t\treturn super.isAbortError( error )\n\t}\n}"]}
|
package/dist/abort.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/abort.ts"],"sourcesContent":["import { Exception, ExceptionOptions } from '.'\nimport { ErrorCode } from './code'\n\n/**\n * Interface representing the options for an Exception.\n *\n * @extends ExceptionOptions\n */\nexport interface AbortErrorOptions extends Omit<ExceptionOptions, 'code' | 'name'>\n{\n\t/** The HTTP status code associated with the Exception. */\n\tstatus?: number\n}\n\n\n/**\n * Exception Class.\n * \n * @template TMessage The type of the message property of the Exception. Defaults to `string`.\n *\n * @extends Exception\n */\nexport class AbortError<TMessage> extends Exception<TMessage, ErrorCode.ABORT> implements AbortErrorOptions\n{\n\tconstructor( reason: TMessage, options?: AbortErrorOptions )\n\t{\n\t\tsuper( reason, { name: 'AbortError', code: ErrorCode.ABORT, ...options } )\n\t}\n\n\n\t/**\n\t * Determines if the provided error is an instance of the AbortError class and has the ABORT ErrorCode.\n\t * \n\t * This won't work for `new DOMException( 'Abort reason', 'AbortError' )` since we type guard the checked value to `AbortError<TMessage>`.\n\t *\n\t * @template TMessage The type of the message property of the AbortError.\n\t * \n\t * @param\terror The error to check.\n\t * @returns\t`true` if the error is an `AbortError` and has the ABORT ErrorCode, `false` otherwise.\n\t */\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tstatic isAbortError<TMessage = string>( error: any ): error is AbortError<TMessage>\n\t{\n\t\treturn super.isAbortError( error )\n\t}\n}"],"mappings":"sEAsBO,IAAMA,EAAN,cAAmCC,CAC1C,CACC,YAAaC,EAAkBC,EAC/B,CACC,MAAOD,EAAQ,CAAE,KAAM,aAAc,iBAAuB,GAAGC,CAAQ,CAAE,CAC1E,CAcA,OAAO,aAAiCC,EACxC,CACC,OAAO,MAAM,aAAcA,CAAM,CAClC,CACD","names":["AbortError","Exception","reason","options","error"]}
|
package/dist/chunk-CLZRQMJF.mjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
var o=class t extends Error{constructor(e,s){super("",s),this.__typename="Exception",this.name=s.name||this.__typename,this.message=e,this.code=s.code,this.status=s.status}static isException(e){return e instanceof t||typeof e=="object"&&"__typename"in e&&e.__typename==="Exception"}static isAbortError(e){return t.isException(e)&&(e.name==="AbortError"||e.code==="ERR:ABORT")}toJSON(){return{...this,message:this.message,cause:this.cause}}};export{o as a};
|
|
2
|
-
//# sourceMappingURL=chunk-CLZRQMJF.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { ErrorCode } from './code'\n\n/**\n * Interface representing the options for an Exception.\n *\n * @template TCode The type of the error code.\n * @extends ErrorOptions\n */\nexport interface ExceptionOptions<TCode = ErrorCode> extends ErrorOptions\n{\n\t/** The error code associated with the Exception. */\n\tcode: TCode\n\t/** The name of the Exception. */\n\tname?: string\n\t/** The HTTP status code associated with the Exception. */\n\tstatus?: number\n}\n\n\n/**\n * Exception Class.\n * \n * @template TMessage\tThe type of the message property of the Exception. Defaults to `string`.\n * @template TCode\t\tThe type of the code property of the Exception. Defaults to `ErrorCode`.\n *\n * @extends Error\n * @implements ExceptionOptions<TCode>\n */\nexport class Exception<TMessage = string, TCode = ErrorCode> extends Error implements ExceptionOptions<TCode>\n{\n\t// @ts-expect-error Type 'TMessage' is not assignable to type 'string'.ts(2416)\n\tmessage: TMessage\n\tstatus\n\tname\n\tprivate __typename: 'Exception'\n\tcode\n\n\n\t/**\n\t * Constructs a new Exception instance.\n\t *\n\t * @param message The message describing the exception.\n\t * @param options Additional options for the exception.\n\t */\n\tconstructor( message: TMessage, options: ExceptionOptions<TCode> ) \n\t{\n\t\tsuper( '', options )\n\n\t\tthis.__typename\t= 'Exception'\n\t\tthis.name\t\t= options.name || this.__typename\n\t\tthis.message\t= message\n\t\tthis.code\t\t= options.code\n\t\tthis.status\t\t= options.status\n\t}\n\n\t\n\t\n\t/**\n\t * Determines if the provided error is an instance of the Exception class.\n\t *\n\t * @template TMessage\tThe type of the message property of the Exception.\n\t * @template TCode\t\tThe type of the code property of the Exception.\n\t * \n\t * @param\terror The error to check.\n\t * @returns\t`true` if the error is an instance of Exception or has a `__typename` property equal to 'Exception', `false` otherwise.\n\t */\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tstatic isException<TMessage = string, TCode = ErrorCode>( error: any ): error is Exception<TMessage, TCode>\n\t{\n\t\treturn (\n\t\t\terror instanceof Exception ||\n\t\t\t( typeof error === 'object' && '__typename' in error && error.__typename === 'Exception' )\n\t\t)\n\t}\n\t\n\n\t/**\n\t * Determines if the provided error is an instance of the Exception class and has the ABORT ErrorCode.\n\t * \n\t * This won't work for `new DOMException( 'Abort reason', 'AbortError' )` since we type guard the checked value to `Exception<TMessage, ErrorCode.ABORT>`.\n\t *\n\t * @template TMessage The type of the message property of the Exception.\n\t * \n\t * @param\terror The error to check.\n\t * @returns\t`true` if the error is an `Exception` and has the ABORT ErrorCode, `false` otherwise.\n\t */\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tstatic isAbortError<TMessage = string>( error: any ): error is Exception<TMessage, ErrorCode.ABORT>\n\t{\n\t\treturn (\n\t\t\tException.isException( error ) &&\n\t\t\t( error.name === 'AbortError' || error.code === ErrorCode.ABORT )\n\t\t)\n\t}\n\n\n\t/**\n\t * Converts the instance to a JSON object.\n\t *\n\t * @returns A JSON representation of the instance, including the message property.\n\t */\n\ttoJSON()\n\t{\n\t\treturn {\n\t\t\t...this,\n\t\t\tmessage\t: this.message,\n\t\t\tcause\t: this.cause,\n\t\t}\n\t}\n}"],"mappings":"AA4BO,IAAMA,EAAN,MAAMC,UAAwD,KACrE,CAeC,YAAaC,EAAmBC,EAChC,CACC,MAAO,GAAIA,CAAQ,EAEnB,KAAK,WAAa,YAClB,KAAK,KAAQA,EAAQ,MAAQ,KAAK,WAClC,KAAK,QAAUD,EACf,KAAK,KAAQC,EAAQ,KACrB,KAAK,OAAUA,EAAQ,MACxB,CAcA,OAAO,YAAmDC,EAC1D,CACC,OACCA,aAAiBH,GACf,OAAOG,GAAU,UAAY,eAAgBA,GAASA,EAAM,aAAe,WAE/E,CAcA,OAAO,aAAiCA,EACxC,CACC,OACCH,EAAU,YAAaG,CAAM,IAC3BA,EAAM,OAAS,cAAgBA,EAAM,OAAS,YAElD,CAQA,QACA,CACC,MAAO,CACN,GAAG,KACH,QAAU,KAAK,QACf,MAAQ,KAAK,KACd,CACD,CACD","names":["Exception","_Exception","message","options","error"]}
|
package/dist/chunk-FXYDTIUG.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var E=(R=>(R.UNKNOWN="ERR:UNKNOWN",R.ABORT="ERR:ABORT",R.EMPTY_VALUE="ERR:EMPTYVALUE",R.WRONG_VALUE="ERR:WRONGVALUE",R.EXPIRED="ERR:EXPIRED",R.TOO_EARLY="ERR:TOOEARLY",R))(E||{});exports.a = E;
|
|
2
|
-
//# sourceMappingURL=chunk-FXYDTIUG.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/code.ts"],"names":["ErrorCode"],"mappings":"AAIO,6EAAKA,CAAAA,CAAAA,CAAAA,CAAAA,EAAAA,CAEXA,CAAAA,CAAA,OAAA,CAAW,aAAA,CACXA,CAAAA,CAAA,KAAA,CAAS,WAAA,CACTA,CAAAA,CAAA,WAAA,CAAc,gBAAA,CACdA,CAAAA,CAAA,WAAA,CAAc,gBAAA,CACdA,CAAAA,CAAA,OAAA,CAAW,aAAA,CACXA,CAAAA,CAAA,SAAA,CAAY,cAAA,CAPDA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,EAAA,CAAA,CAAA,CAAA,CAAA,cAAA","file":"/Users/alessio/Documents/Personal/projects/exception/dist/chunk-FXYDTIUG.js","sourcesContent":["/**\n * Most common error codes.\n * \n */\nexport enum ErrorCode\n{\n\tUNKNOWN\t\t= 'ERR:UNKNOWN',\n\tABORT\t\t= 'ERR:ABORT',\n\tEMPTY_VALUE\t= 'ERR:EMPTYVALUE',\n\tWRONG_VALUE\t= 'ERR:WRONGVALUE',\n\tEXPIRED\t\t= 'ERR:EXPIRED',\n\tTOO_EARLY\t= 'ERR:TOOEARLY',\n}"]}
|
package/dist/chunk-JM2G32JS.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/code.ts"],"sourcesContent":["/**\n * Most common error codes.\n * \n */\nexport enum ErrorCode\n{\n\tUNKNOWN\t\t= 'ERR:UNKNOWN',\n\tABORT\t\t= 'ERR:ABORT',\n\tEMPTY_VALUE\t= 'ERR:EMPTYVALUE',\n\tWRONG_VALUE\t= 'ERR:WRONGVALUE',\n\tEXPIRED\t\t= 'ERR:EXPIRED',\n\tTOO_EARLY\t= 'ERR:TOOEARLY',\n}"],"mappings":"AAIO,IAAKA,OAEXA,EAAA,QAAW,cACXA,EAAA,MAAS,YACTA,EAAA,YAAc,iBACdA,EAAA,YAAc,iBACdA,EAAA,QAAW,cACXA,EAAA,UAAY,eAPDA,OAAA","names":["ErrorCode"]}
|
package/dist/chunk-OJYXDMWZ.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var o=class t extends Error{constructor(e,s){super("",s),this.__typename="Exception",this.name=s.name||this.__typename,this.message=e,this.code=s.code,this.status=s.status}static isException(e){return e instanceof t||typeof e=="object"&&"__typename"in e&&e.__typename==="Exception"}static isAbortError(e){return t.isException(e)&&(e.name==="AbortError"||e.code==="ERR:ABORT")}toJSON(){return{...this,message:this.message,cause:this.cause}}};exports.a = o;
|
|
2
|
-
//# sourceMappingURL=chunk-OJYXDMWZ.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":["Exception","_Exception","message","options","error"],"mappings":"AA4BO,6EAAMA,CAAAA,CAAN,MAAMC,EAAAA,QAAwD,KACrE,CAeC,WAAA,CAAaC,CAAAA,CAAmBC,CAAAA,CAChC,CACC,KAAA,CAAO,EAAA,CAAIA,CAAQ,CAAA,CAEnB,IAAA,CAAK,UAAA,CAAa,WAAA,CAClB,IAAA,CAAK,IAAA,CAAQA,CAAAA,CAAQ,IAAA,EAAQ,IAAA,CAAK,UAAA,CAClC,IAAA,CAAK,OAAA,CAAUD,CAAAA,CACf,IAAA,CAAK,IAAA,CAAQC,CAAAA,CAAQ,IAAA,CACrB,IAAA,CAAK,MAAA,CAAUA,CAAAA,CAAQ,MACxB,CAcA,OAAO,WAAA,CAAmDC,CAAAA,CAC1D,CACC,OACCA,EAAAA,WAAiBH,CAAAA,EACf,OAAOG,CAAAA,EAAU,QAAA,EAAY,YAAA,GAAgBA,CAAAA,EAASA,CAAAA,CAAM,UAAA,GAAe,WAE/E,CAcA,OAAO,YAAA,CAAiCA,CAAAA,CACxC,CACC,OACCH,CAAAA,CAAU,WAAA,CAAaG,CAAM,CAAA,EAAA,CAC3BA,CAAAA,CAAM,IAAA,GAAS,YAAA,EAAgBA,CAAAA,CAAM,IAAA,GAAS,WAAA,CAElD,CAQA,MAAA,CAAA,CACA,CACC,MAAO,CACN,GAAG,IAAA,CACH,OAAA,CAAU,IAAA,CAAK,OAAA,CACf,KAAA,CAAQ,IAAA,CAAK,KACd,CACD,CACD,CAAA,CAAA,cAAA","file":"/Users/alessio/Documents/Personal/projects/exception/dist/chunk-OJYXDMWZ.js","sourcesContent":["import { ErrorCode } from './code'\n\n/**\n * Interface representing the options for an Exception.\n *\n * @template TCode The type of the error code.\n * @extends ErrorOptions\n */\nexport interface ExceptionOptions<TCode = ErrorCode> extends ErrorOptions\n{\n\t/** The error code associated with the Exception. */\n\tcode: TCode\n\t/** The name of the Exception. */\n\tname?: string\n\t/** The HTTP status code associated with the Exception. */\n\tstatus?: number\n}\n\n\n/**\n * Exception Class.\n * \n * @template TMessage\tThe type of the message property of the Exception. Defaults to `string`.\n * @template TCode\t\tThe type of the code property of the Exception. Defaults to `ErrorCode`.\n *\n * @extends Error\n * @implements ExceptionOptions<TCode>\n */\nexport class Exception<TMessage = string, TCode = ErrorCode> extends Error implements ExceptionOptions<TCode>\n{\n\t// @ts-expect-error Type 'TMessage' is not assignable to type 'string'.ts(2416)\n\tmessage: TMessage\n\tstatus\n\tname\n\tprivate __typename: 'Exception'\n\tcode\n\n\n\t/**\n\t * Constructs a new Exception instance.\n\t *\n\t * @param message The message describing the exception.\n\t * @param options Additional options for the exception.\n\t */\n\tconstructor( message: TMessage, options: ExceptionOptions<TCode> ) \n\t{\n\t\tsuper( '', options )\n\n\t\tthis.__typename\t= 'Exception'\n\t\tthis.name\t\t= options.name || this.__typename\n\t\tthis.message\t= message\n\t\tthis.code\t\t= options.code\n\t\tthis.status\t\t= options.status\n\t}\n\n\t\n\t\n\t/**\n\t * Determines if the provided error is an instance of the Exception class.\n\t *\n\t * @template TMessage\tThe type of the message property of the Exception.\n\t * @template TCode\t\tThe type of the code property of the Exception.\n\t * \n\t * @param\terror The error to check.\n\t * @returns\t`true` if the error is an instance of Exception or has a `__typename` property equal to 'Exception', `false` otherwise.\n\t */\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tstatic isException<TMessage = string, TCode = ErrorCode>( error: any ): error is Exception<TMessage, TCode>\n\t{\n\t\treturn (\n\t\t\terror instanceof Exception ||\n\t\t\t( typeof error === 'object' && '__typename' in error && error.__typename === 'Exception' )\n\t\t)\n\t}\n\t\n\n\t/**\n\t * Determines if the provided error is an instance of the Exception class and has the ABORT ErrorCode.\n\t * \n\t * This won't work for `new DOMException( 'Abort reason', 'AbortError' )` since we type guard the checked value to `Exception<TMessage, ErrorCode.ABORT>`.\n\t *\n\t * @template TMessage The type of the message property of the Exception.\n\t * \n\t * @param\terror The error to check.\n\t * @returns\t`true` if the error is an `Exception` and has the ABORT ErrorCode, `false` otherwise.\n\t */\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tstatic isAbortError<TMessage = string>( error: any ): error is Exception<TMessage, ErrorCode.ABORT>\n\t{\n\t\treturn (\n\t\t\tException.isException( error ) &&\n\t\t\t( error.name === 'AbortError' || error.code === ErrorCode.ABORT )\n\t\t)\n\t}\n\n\n\t/**\n\t * Converts the instance to a JSON object.\n\t *\n\t * @returns A JSON representation of the instance, including the message property.\n\t */\n\ttoJSON()\n\t{\n\t\treturn {\n\t\t\t...this,\n\t\t\tmessage\t: this.message,\n\t\t\tcause\t: this.cause,\n\t\t}\n\t}\n}"]}
|
package/dist/code.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/alessio/Documents/Personal/projects/exception/dist/code.js"],"names":[],"mappings":"AAAA,+HAAkC,uCAAuB","file":"/Users/alessio/Documents/Personal/projects/exception/dist/code.js"}
|
package/dist/code.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/alessio/Documents/Personal/projects/exception/dist/index.js"],"names":[],"mappings":"AAAA,+HAAkC,+BAA4B,uCAAuB","file":"/Users/alessio/Documents/Personal/projects/exception/dist/index.js"}
|
package/dist/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|