@alessiofrittoli/exception 3.1.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 +22 -20
- 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.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-4PCRWQET.js +0 -2
- package/dist/chunk-4PCRWQET.js.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-PPUBHX7P.mjs +0 -2
- package/dist/chunk-PPUBHX7P.mjs.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)
|
|
@@ -160,9 +162,9 @@ The constructor initializes an `AbortError` instance with a custom message and o
|
|
|
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,7 +196,7 @@ try {
|
|
|
194
196
|
|
|
195
197
|
---
|
|
196
198
|
|
|
197
|
-
|
|
199
|
+
###### Using custom Abort Error codes
|
|
198
200
|
|
|
199
201
|
```ts
|
|
200
202
|
import { AbortError } from '@alessiofrittoli/exception/abort'
|
|
@@ -242,14 +244,18 @@ It is designed to simplify error handling and improve feedback quality returned
|
|
|
242
244
|
|
|
243
245
|
<summary>Constants Overview</summary>
|
|
244
246
|
|
|
245
|
-
| Constant
|
|
246
|
-
|
|
247
|
-
| `UNKNOWN`
|
|
248
|
-
| `ABORT`
|
|
249
|
-
| `EMPTY_VALUE`
|
|
250
|
-
| `WRONG_VALUE`
|
|
251
|
-
| `EXPIRED`
|
|
252
|
-
| `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. |
|
|
253
259
|
|
|
254
260
|
</details>
|
|
255
261
|
|
|
@@ -285,11 +291,9 @@ export default ErrorCode
|
|
|
285
291
|
|
|
286
292
|
---
|
|
287
293
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
<summary>Usage</summary>
|
|
294
|
+
#### Examples
|
|
291
295
|
|
|
292
|
-
|
|
296
|
+
##### Using the default `ErrorCode` to throw a new `Exception`
|
|
293
297
|
|
|
294
298
|
```ts
|
|
295
299
|
import { Exception } from '@alessiofrittoli/exception'
|
|
@@ -301,7 +305,7 @@ throw new Exception( 'Password is a required field to log you in.', {
|
|
|
301
305
|
} )
|
|
302
306
|
```
|
|
303
307
|
|
|
304
|
-
|
|
308
|
+
##### Using custom `ErrorCode` to throw a new `Exception`
|
|
305
309
|
|
|
306
310
|
```ts
|
|
307
311
|
import { Exception } from '@alessiofrittoli/exception'
|
|
@@ -313,7 +317,7 @@ throw new Exception( 'Invalid signature.', {
|
|
|
313
317
|
} )
|
|
314
318
|
```
|
|
315
319
|
|
|
316
|
-
|
|
320
|
+
##### Using `ErrorCode` to handle errors
|
|
317
321
|
|
|
318
322
|
```ts
|
|
319
323
|
import { ErrorCode } from '@/error-code' // previously created in `myproject/src/error-code.ts`
|
|
@@ -334,8 +338,6 @@ try {
|
|
|
334
338
|
}
|
|
335
339
|
```
|
|
336
340
|
|
|
337
|
-
</details>
|
|
338
|
-
|
|
339
341
|
---
|
|
340
342
|
|
|
341
343
|
### Development
|
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.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","name","code","rest","error"],"mappings":"AAAA,+HAAuC,+BAA4B,ICsBtDA,CAAAA,CAAN,MAAA,QAEGC,kBACV,CACC,WAAA,CAAaC,CAAAA,CAAkBC,CAAAA,CAAoC,CAAC,CAAA,CACpE,CACC,IAAMC,CAAAA,CAAO,YAAA,CAEP,CACL,IAAA,CAAAC,CAAAA,CAAAA,WAAAA,CAAiC,GAAGC,CACrC,CAAA,CAAIH,CAAAA,CAEJ,KAAA,CAAOD,CAAAA,CAAQ,CAAE,GAAGI,CAAAA,CAAM,IAAA,CAAAF,CAAAA,CAAM,IAAA,CAAAC,CAAK,CAAE,CACxC,CAaA,OAAO,YAAA,CAGJE,CAAAA,CAAYF,CAAAA,CACf,CACC,OAAO,KAAA,CAAM,YAAA,CAAcE,CAAAA,CAAOF,CAAK,CACxC,CACD,CAAA,CAAA,uBAAA","file":"/Users/alessio/Documents/Personal/projects/exception/dist/abort.js","sourcesContent":[null,"import { Exception, type ExceptionOptions } from '.'\nimport { ErrorCode } from './code'\n\n/**\n * Interface representing the options for an Exception.\n *\n * @extends ExceptionOptions\n */\nexport interface AbortErrorOptions<TCode = ErrorCode> extends Partial<Omit<ExceptionOptions<TCode>, '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<\n\tTMessage = string, TCode = ErrorCode\n> extends Exception<TMessage, TCode> implements AbortErrorOptions<TCode>\n{\n\tconstructor( reason: TMessage, options: AbortErrorOptions<TCode> = {} )\n\t{\n\t\tconst name = 'AbortError'\n\n\t\tconst {\n\t\t\tcode = ErrorCode.ABORT as TCode, ...rest\n\t\t} = options\n\n\t\tsuper( reason, { ...rest, name, code } )\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\tstatic isAbortError<\n\t\tTMessage = string, TCode = ErrorCode\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t>( error: any, code?: TCode ): error is AbortError<TMessage, TCode>\n\t{\n\t\treturn super.isAbortError( error, code )\t\n\t}\n}"]}
|
package/dist/abort.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/abort.ts"],"sourcesContent":["import { Exception, type ExceptionOptions } from '.'\nimport { ErrorCode } from './code'\n\n/**\n * Interface representing the options for an Exception.\n *\n * @extends ExceptionOptions\n */\nexport interface AbortErrorOptions<TCode = ErrorCode> extends Partial<Omit<ExceptionOptions<TCode>, '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<\n\tTMessage = string, TCode = ErrorCode\n> extends Exception<TMessage, TCode> implements AbortErrorOptions<TCode>\n{\n\tconstructor( reason: TMessage, options: AbortErrorOptions<TCode> = {} )\n\t{\n\t\tconst name = 'AbortError'\n\n\t\tconst {\n\t\t\tcode = ErrorCode.ABORT as TCode, ...rest\n\t\t} = options\n\n\t\tsuper( reason, { ...rest, name, code } )\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\tstatic isAbortError<\n\t\tTMessage = string, TCode = ErrorCode\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t>( error: any, code?: TCode ): error is AbortError<TMessage, TCode>\n\t{\n\t\treturn super.isAbortError( error, code )\t\n\t}\n}"],"mappings":"sEAsBO,IAAMA,EAAN,cAEGC,CACV,CACC,YAAaC,EAAkBC,EAAoC,CAAC,EACpE,CACC,IAAMC,EAAO,aAEP,CACL,KAAAC,cAAiC,GAAGC,CACrC,EAAIH,EAEJ,MAAOD,EAAQ,CAAE,GAAGI,EAAM,KAAAF,EAAM,KAAAC,CAAK,CAAE,CACxC,CAaA,OAAO,aAGJE,EAAYF,EACf,CACC,OAAO,MAAM,aAAcE,EAAOF,CAAK,CACxC,CACD","names":["AbortError","Exception","reason","options","name","code","rest","error"]}
|
package/dist/chunk-4PCRWQET.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,s="ERR:ABORT"){return t.isException(e)&&(e.name==="AbortError"||e.code===s)}toJSON(){return{...this,message:this.message,cause:this.cause}}};exports.a = o;
|
|
2
|
-
//# sourceMappingURL=chunk-4PCRWQET.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":["Exception","_Exception","message","options","error","code"],"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,CAaA,OAAO,YAAA,CAENA,CAAAA,CAAYC,CAAAA,CAAAA,WAAAA,CAEb,CACC,OACCJ,CAAAA,CAAU,WAAA,CAAaG,CAAM,CAAA,EAAA,CAC3BA,CAAAA,CAAM,IAAA,GAAS,YAAA,EAAgBA,CAAAA,CAAM,IAAA,GAASC,CAAAA,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-4PCRWQET.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\tstatic isAbortError<TMessage = string, TCode = ErrorCode>(\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\terror: any, code: TCode = ErrorCode.ABORT as TCode\n\t): error is Exception<TMessage, TCode>\n\t{\n\t\treturn (\n\t\t\tException.isException( error ) &&\n\t\t\t( error.name === 'AbortError' || error.code === code )\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/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-PPUBHX7P.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,s="ERR:ABORT"){return t.isException(e)&&(e.name==="AbortError"||e.code===s)}toJSON(){return{...this,message:this.message,cause:this.cause}}};export{o as a};
|
|
2
|
-
//# sourceMappingURL=chunk-PPUBHX7P.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\tstatic isAbortError<TMessage = string, TCode = ErrorCode>(\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\terror: any, code: TCode = ErrorCode.ABORT as TCode\n\t): error is Exception<TMessage, TCode>\n\t{\n\t\treturn (\n\t\t\tException.isException( error ) &&\n\t\t\t( error.name === 'AbortError' || error.code === code )\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,CAaA,OAAO,aAENA,EAAYC,cAEb,CACC,OACCJ,EAAU,YAAaG,CAAM,IAC3BA,EAAM,OAAS,cAAgBA,EAAM,OAASC,EAElD,CAQA,QACA,CACC,MAAO,CACN,GAAG,KACH,QAAU,KAAK,QACf,MAAQ,KAAK,KACd,CACD,CACD","names":["Exception","_Exception","message","options","error","code"]}
|
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":[]}
|