@alessiofrittoli/exception 3.1.0 → 3.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.
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
- - [Usage Scenarios](#usage-scenarios)
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
- #### Usage Scenarios
165
+ ##### AbortError Usage Scenarios
164
166
 
165
- ##### Precise Abort Errors Handling
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
- ##### Using custom Abort Error codes
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 | Value | Description |
246
- |---------------|------------------|---------------------------------------------------------|
247
- | `UNKNOWN` | `ERR:UNKNOWN` | Returned when an unexpected error occured. |
248
- | `ABORT` | `ERR:ABORT` | Returned when user abort the request. |
249
- | `EMPTY_VALUE` | `ERR:EMPTYVALUE` | Returned when a required value is "falsy". |
250
- | `WRONG_VALUE` | `ERR:WRONGVALUE` | Return when a required value is not the expected value. |
251
- | `EXPIRED` | `ERR:EXPIRED` | Returned when a requested has been performed too late. |
252
- | `TOO_EARLY` | `ERR:TOOEARLY` | Returned when a request has been performed 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
- <details>
289
-
290
- <summary>Usage</summary>
294
+ #### Examples
291
295
 
292
- #### Using the default `ErrorCode` to throw a new `Exception`
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
- #### Using custom `ErrorCode` to throw a new `Exception`
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
- #### Using `ErrorCode` to handle errors
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 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunk4PCRWQETjs = require('./chunk-4PCRWQET.js');require('./chunk-FXYDTIUG.js');var t=class extends _chunk4PCRWQETjs.a{constructor(r,o={}){let s="AbortError",{code:n="ERR:ABORT",...i}=o;super(r,{...i,name:s,code:n})}static isAbortError(r,o){return super.isAbortError(r,o)}};exports.AbortError = t;
2
- //# sourceMappingURL=abort.js.map
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkYQB23ERMjs = require('./chunk-YQB23ERM.js');require('./chunk-5TBITEFP.js');var t=class extends _chunkYQB23ERMjs.a{constructor(r,o={}){let s="AbortError",{code:n="ERR:ABORT",...i}=o;super(r,{...i,name:s,code:n})}static isAbortError(r,o){return super.isAbortError(r,o)}};exports.AbortError = t;
package/dist/abort.mjs CHANGED
@@ -1,2 +1 @@
1
- import{a as e}from"./chunk-PPUBHX7P.mjs";import"./chunk-JM2G32JS.mjs";var t=class extends e{constructor(r,o={}){let s="AbortError",{code:n="ERR:ABORT",...i}=o;super(r,{...i,name:s,code:n})}static isAbortError(r,o){return super.isAbortError(r,o)}};export{t as AbortError};
2
- //# sourceMappingURL=abort.mjs.map
1
+ import{a as e}from"./chunk-LFZW7VUK.mjs";import"./chunk-F4EU4T25.mjs";var t=class extends e{constructor(r,o={}){let s="AbortError",{code:n="ERR:ABORT",...i}=o;super(r,{...i,name:s,code:n})}static isAbortError(r,o){return super.isAbortError(r,o)}};export{t as AbortError};
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var O=(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.TOO_MANY="ERR:TOOMANY",R.QUOTA_REACHED="ERR:QUOTAREACHED",R.NOT_FOUND="ERR:NOTFOUND",R.OFFLINE="ERR:INTERNETDISCONNECTED",R))(O||{});exports.a = O;
@@ -0,0 +1 @@
1
+ var O=(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.TOO_MANY="ERR:TOOMANY",R.QUOTA_REACHED="ERR:QUOTAREACHED",R.NOT_FOUND="ERR:NOTFOUND",R.OFFLINE="ERR:INTERNETDISCONNECTED",R))(O||{});export{O as a};
@@ -1,2 +1 @@
1
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,2 +1 @@
1
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
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 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkFXYDTIUGjs = require('./chunk-FXYDTIUG.js');exports.ErrorCode = _chunkFXYDTIUGjs.a;
2
- //# sourceMappingURL=code.js.map
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunk5TBITEFPjs = require('./chunk-5TBITEFP.js');exports.ErrorCode = _chunk5TBITEFPjs.a;
package/dist/code.mjs CHANGED
@@ -1,2 +1 @@
1
- import{a}from"./chunk-JM2G32JS.mjs";export{a as ErrorCode};
2
- //# sourceMappingURL=code.mjs.map
1
+ import{a}from"./chunk-F4EU4T25.mjs";export{a as ErrorCode};
package/dist/index.js CHANGED
@@ -1,2 +1 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunk4PCRWQETjs = require('./chunk-4PCRWQET.js');require('./chunk-FXYDTIUG.js');exports.Exception = _chunk4PCRWQETjs.a;
2
- //# sourceMappingURL=index.js.map
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkYQB23ERMjs = require('./chunk-YQB23ERM.js');require('./chunk-5TBITEFP.js');exports.Exception = _chunkYQB23ERMjs.a;
package/dist/index.mjs CHANGED
@@ -1,2 +1 @@
1
- import{a}from"./chunk-PPUBHX7P.mjs";import"./chunk-JM2G32JS.mjs";export{a as Exception};
2
- //# sourceMappingURL=index.mjs.map
1
+ import{a}from"./chunk-LFZW7VUK.mjs";import"./chunk-F4EU4T25.mjs";export{a as Exception};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alessiofrittoli/exception",
3
- "version": "3.1.0",
3
+ "version": "3.3.0",
4
4
  "description": "Handle errors with ease",
5
5
  "author": {
6
6
  "name": "Alessio Frittoli",
@@ -35,30 +35,46 @@
35
35
  ],
36
36
  "exports": {
37
37
  ".": {
38
- "types": "./dist/index.d.ts",
39
- "import": "./dist/index.mjs",
40
- "require": "./dist/index.js"
38
+ "import": {
39
+ "types": "./dist/index.d.mts",
40
+ "default": "./dist/index.mjs"
41
+ },
42
+ "require": {
43
+ "types": "./dist/index.d.ts",
44
+ "default": "./dist/index.js"
45
+ }
41
46
  },
42
47
  "./code": {
43
- "types": "./dist/code.d.ts",
44
- "import": "./dist/code.mjs",
45
- "require": "./dist/code.js"
48
+ "import": {
49
+ "types": "./dist/code.d.mts",
50
+ "default": "./dist/code.mjs"
51
+ },
52
+ "require": {
53
+ "types": "./dist/code.d.ts",
54
+ "default": "./dist/code.js"
55
+ }
46
56
  },
47
57
  "./abort": {
48
- "types": "./dist/abort.d.ts",
49
- "import": "./dist/abort.mjs",
50
- "require": "./dist/abort.js"
58
+ "import": {
59
+ "types": "./dist/abort.d.mts",
60
+ "default": "./dist/abort.mjs"
61
+ },
62
+ "require": {
63
+ "types": "./dist/abort.d.ts",
64
+ "default": "./dist/abort.js"
65
+ }
51
66
  }
52
67
  },
53
68
  "sideEffects": false,
54
69
  "scripts": {
55
70
  "//1a": "*********************************************************************",
56
- "//1b": "*********************** BUILD - LINT - RELEASE **********************",
71
+ "//1b": "******************** DEV - BUILD - LINT - RELEASE *******************",
57
72
  "//1c": "*********************************************************************",
58
- "build": "pnpm lint && pnpm test:ci && tsup",
59
- "build:watch": "tsup --watch",
73
+ "dev": "cross-env NODE_ENV=development tsup --watch",
74
+ "build:prod": "cross-env NODE_ENV=production tsup",
75
+ "build": "pnpm lint && pnpm test:ci && pnpm build:prod",
60
76
  "lint": "eslint",
61
- "release": "node scripts/publish.js --verbose --npm",
77
+ "release": "node scripts/release.js --verbose --npm",
62
78
  "//2a": "*********************************************************************",
63
79
  "//2b": "***************************** UNIT TESTS ****************************",
64
80
  "//2c": "*********************************************************************",
@@ -74,27 +90,23 @@
74
90
  "test:coverage:serve": "concurrently --prefix none --kill-others \"pnpm test:coverage\" \"pnpm test:serve-coverage\""
75
91
  },
76
92
  "devDependencies": {
77
- "@alessiofrittoli/node-scripts": "^2.4.0",
78
- "@eslint/js": "^9.25.1",
79
- "@jest/globals": "^29.7.0",
80
- "@types/jest": "^29.5.14",
81
- "@types/node": "^22.15.2",
82
- "concurrently": "^9.1.2",
83
- "dotenv": "^16.5.0",
84
- "esbuild": "0.25.3",
85
- "eslint": "^9.25.1",
86
- "globals": "^16.0.0",
93
+ "@alessiofrittoli/node-scripts": "^3.2.0",
94
+ "@eslint/js": "^9.39.1",
95
+ "@jest/globals": "^30.2.0",
96
+ "@types/jest": "^30.0.0",
97
+ "@types/node": "^24.10.1",
98
+ "concurrently": "^9.2.1",
99
+ "cross-env": "^10.1.0",
100
+ "dotenv": "^17.2.3",
101
+ "esbuild": "0.27.0",
102
+ "eslint": "^9.39.1",
103
+ "globals": "^16.5.0",
87
104
  "http-server": "^14.1.1",
88
- "jest": "^29.7.0",
89
- "ts-jest": "^29.3.2",
105
+ "jest": "^30.2.0",
106
+ "ts-jest": "^29.4.6",
90
107
  "ts-node": "^10.9.2",
91
- "tsup": "^8.4.0",
92
- "typescript": "^5.8.3",
93
- "typescript-eslint": "^8.31.0"
94
- },
95
- "pnpm": {
96
- "onlyBuiltDependencies": [
97
- "esbuild"
98
- ]
108
+ "tsup": "^8.5.1",
109
+ "typescript": "^5.9.3",
110
+ "typescript-eslint": "^8.48.1"
99
111
  }
100
112
  }
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}"]}
@@ -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"]}
@@ -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}"]}
@@ -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}"]}
@@ -1,2 +0,0 @@
1
- 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||{});export{E as a};
2
- //# sourceMappingURL=chunk-JM2G32JS.mjs.map
@@ -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"]}
@@ -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"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}