@alessiofrittoli/exception 1.2.0 → 2.0.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 +10 -8
- package/dist/code.d.mts +1 -1
- package/dist/code.d.ts +1 -1
- package/dist/code.js +1 -1
- package/dist/code.mjs +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +15 -8
package/README.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# Exception 🚦
|
|
2
2
|
|
|
3
|
-
Version
|
|
3
|
+
Version 2.0.0
|
|
4
|
+
|
|
5
|
+
[](https://coveralls.io/github/alessiofrittoli/exception) [](https://libraries.io/npm/%40alessiofrittoli%2Fexception)
|
|
4
6
|
|
|
5
7
|
## Handle errors with ease
|
|
6
8
|
|
|
@@ -76,7 +78,7 @@ The constructor initializes an `Exception` instance with a custom message and op
|
|
|
76
78
|
###### Example
|
|
77
79
|
|
|
78
80
|
```ts
|
|
79
|
-
import Exception from '@alessiofrittoli/exception'
|
|
81
|
+
import { Exception } from '@alessiofrittoli/exception'
|
|
80
82
|
|
|
81
83
|
try {
|
|
82
84
|
throw new Exception( 'Resource not found', {
|
|
@@ -178,7 +180,7 @@ To fill this gap, you can "extend" the `ErrorCode` enum by doing so:
|
|
|
178
180
|
|
|
179
181
|
```ts
|
|
180
182
|
// myproject/src/error-code.ts
|
|
181
|
-
import ExceptionCode from '@alessiofrittoli/exception/code'
|
|
183
|
+
import { ExceptionCode } from '@alessiofrittoli/exception/code'
|
|
182
184
|
|
|
183
185
|
/** Your project custom `ErrorCode`. */
|
|
184
186
|
export enum MyProjectErrorCode
|
|
@@ -205,8 +207,8 @@ export default ErrorCode
|
|
|
205
207
|
#### Using the default `ErrorCode` to throw a new `Exception`
|
|
206
208
|
|
|
207
209
|
```ts
|
|
208
|
-
import Exception from '@alessiofrittoli/exception'
|
|
209
|
-
import ErrorCode from '@alessiofrittoli/exception/code'
|
|
210
|
+
import { Exception } from '@alessiofrittoli/exception'
|
|
211
|
+
import { ErrorCode } from '@alessiofrittoli/exception/code'
|
|
210
212
|
|
|
211
213
|
throw new Exception( 'Password is a required field to log you in.', {
|
|
212
214
|
code : ErrorCode.EMPTY_VALUE,
|
|
@@ -217,8 +219,8 @@ throw new Exception( 'Password is a required field to log you in.', {
|
|
|
217
219
|
#### Using custom `ErrorCode` to throw a new `Exception`
|
|
218
220
|
|
|
219
221
|
```ts
|
|
220
|
-
import Exception from '@alessiofrittoli/exception'
|
|
221
|
-
import ErrorCode from '@/error-code' // previously created in `myproject/src/error-code.ts`
|
|
222
|
+
import { Exception } from '@alessiofrittoli/exception'
|
|
223
|
+
import { ErrorCode } from '@/error-code' // previously created in `myproject/src/error-code.ts`
|
|
222
224
|
|
|
223
225
|
throw new Exception( 'Invalid signature.', {
|
|
224
226
|
code : ErrorCode.MyProjectErrorCode.INVALID_SIGN,
|
|
@@ -229,7 +231,7 @@ throw new Exception( 'Invalid signature.', {
|
|
|
229
231
|
#### Using `ErrorCode` to handle errors
|
|
230
232
|
|
|
231
233
|
```ts
|
|
232
|
-
import ErrorCode from '@/error-code' // previously created in `myproject/src/error-code.ts`
|
|
234
|
+
import { ErrorCode } from '@/error-code' // previously created in `myproject/src/error-code.ts`
|
|
233
235
|
|
|
234
236
|
try {
|
|
235
237
|
...
|
package/dist/code.d.mts
CHANGED
package/dist/code.d.ts
CHANGED
package/dist/code.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';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||{})
|
|
1
|
+
'use strict';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.ErrorCode=E;
|
package/dist/code.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
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||{})
|
|
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 ErrorCode};
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import ErrorCode from './code.mjs';
|
|
1
|
+
import { ErrorCode } from './code.mjs';
|
|
2
2
|
|
|
3
3
|
interface ExceptionOptions<TCode = ErrorCode> extends ErrorOptions {
|
|
4
4
|
code: TCode;
|
|
@@ -15,4 +15,4 @@ declare class Exception<TMessage = string, TCode = ErrorCode> extends Error impl
|
|
|
15
15
|
static isException<TMessage = string, TCode = ErrorCode>(error: any): error is Exception<TMessage, TCode>;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
export { type ExceptionOptions
|
|
18
|
+
export { Exception, type ExceptionOptions };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import ErrorCode from './code.js';
|
|
1
|
+
import { ErrorCode } from './code.js';
|
|
2
2
|
|
|
3
3
|
interface ExceptionOptions<TCode = ErrorCode> extends ErrorOptions {
|
|
4
4
|
code: TCode;
|
|
@@ -15,4 +15,4 @@ declare class Exception<TMessage = string, TCode = ErrorCode> extends Error impl
|
|
|
15
15
|
static isException<TMessage = string, TCode = ErrorCode>(error: any): error is Exception<TMessage, TCode>;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
export { type ExceptionOptions
|
|
18
|
+
export { Exception, type ExceptionOptions };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var s=class o extends Error{
|
|
1
|
+
'use strict';var s=class o extends Error{constructor(e,t){super("",t),this.typename="Exception",this.name=t.name||this.typename,this.message=e,this.code=t.code,this.status=t.status;}static isException(e){return e instanceof o||typeof e=="object"&&"typename"in e&&e.typename==="Exception"}};exports.Exception=s;
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var s=class o extends Error{
|
|
1
|
+
var s=class o extends Error{constructor(e,t){super("",t),this.typename="Exception",this.name=t.name||this.typename,this.message=e,this.code=t.code,this.status=t.status;}static isException(e){return e instanceof o||typeof e=="object"&&"typename"in e&&e.typename==="Exception"}};export{s as Exception};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alessiofrittoli/exception",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Handle errors with ease",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Alessio Frittoli",
|
|
@@ -41,26 +41,33 @@
|
|
|
41
41
|
"sideEffects": false,
|
|
42
42
|
"scripts": {
|
|
43
43
|
"build": "pnpm lint && pnpm test:ci && tsup",
|
|
44
|
+
"build:watch": "tsup --watch",
|
|
44
45
|
"lint": "eslint",
|
|
45
|
-
"
|
|
46
|
-
"test
|
|
46
|
+
"release": "node scripts/publish.js --verbose --npm",
|
|
47
|
+
"test": "pnpm test:watch",
|
|
48
|
+
"test:watch": "jest --watchAll --verbose",
|
|
49
|
+
"test:jsdom": "JSDOM=true pnpm test:watch",
|
|
47
50
|
"test:ci": "jest --ci --verbose",
|
|
48
51
|
"test:ci:jsdom": "JSDOM=true pnpm test:ci",
|
|
52
|
+
"test:coverage": "pnpm test:watch --coverage",
|
|
53
|
+
"test:ci:coverage": "pnpm test:ci --coverage",
|
|
49
54
|
"test:serve-coverage": "http-server ./coverage/lcov-report --gzip true -p 0 -o --silent",
|
|
50
|
-
"test:coverage": "concurrently --prefix none --kill-others \"pnpm
|
|
55
|
+
"test:coverage:serve": "concurrently --prefix none --kill-others \"pnpm test:coverage\" \"pnpm test:serve-coverage\"",
|
|
51
56
|
"test:coverage:jsdom": "JSDOM=true pnpm test:coverage",
|
|
52
|
-
"test:
|
|
57
|
+
"test:coverage:jsdom:serve": "JSDOM=true pnpm test:coverage:serve",
|
|
58
|
+
"test:jest": "pnpm test:watch jest.test.ts",
|
|
53
59
|
"test:jest:jsdom": "JSDOM=true pnpm test:jest",
|
|
54
60
|
"test:exception": "pnpm test exception.test.ts"
|
|
55
61
|
},
|
|
56
62
|
"devDependencies": {
|
|
63
|
+
"@alessiofrittoli/node-scripts": "^2.2.1",
|
|
57
64
|
"@eslint/js": "^9.17.0",
|
|
58
65
|
"@jest/globals": "^29.7.0",
|
|
59
66
|
"@types/jest": "^29.5.14",
|
|
60
67
|
"@types/node": "^22.10.2",
|
|
61
|
-
"concurrently": "^9.1.
|
|
68
|
+
"concurrently": "^9.1.2",
|
|
62
69
|
"dotenv": "^16.4.7",
|
|
63
|
-
"esbuild": "0.24.
|
|
70
|
+
"esbuild": "0.24.2",
|
|
64
71
|
"eslint": "^9.17.0",
|
|
65
72
|
"globals": "^15.14.0",
|
|
66
73
|
"http-server": "^14.1.1",
|
|
@@ -70,6 +77,6 @@
|
|
|
70
77
|
"ts-node": "^10.9.2",
|
|
71
78
|
"tsup": "^8.3.5",
|
|
72
79
|
"typescript": "^5.7.2",
|
|
73
|
-
"typescript-eslint": "^8.
|
|
80
|
+
"typescript-eslint": "^8.19.0"
|
|
74
81
|
}
|
|
75
82
|
}
|