@alessiofrittoli/exception 2.0.0 → 2.1.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 +1 -1
- package/dist/index.d.mts +42 -0
- package/dist/index.d.ts +42 -0
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Exception 🚦
|
|
2
2
|
|
|
3
|
-
Version 2.
|
|
3
|
+
Version 2.1.0
|
|
4
4
|
|
|
5
5
|
[](https://coveralls.io/github/alessiofrittoli/exception) [](https://libraries.io/npm/%40alessiofrittoli%2Fexception)
|
|
6
6
|
|
package/dist/index.d.mts
CHANGED
|
@@ -1,18 +1,60 @@
|
|
|
1
1
|
import { ErrorCode } from './code.mjs';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Interface representing the options for an Exception.
|
|
5
|
+
*
|
|
6
|
+
* @template TCode - The type of the error code.
|
|
7
|
+
* @extends ErrorOptions
|
|
8
|
+
*/
|
|
3
9
|
interface ExceptionOptions<TCode = ErrorCode> extends ErrorOptions {
|
|
10
|
+
/** The error code associated with the Exception. */
|
|
4
11
|
code: TCode;
|
|
12
|
+
/** The name of the Exception. */
|
|
5
13
|
name?: string;
|
|
14
|
+
/** The HTTP status code associated with the Exception. */
|
|
6
15
|
status?: number;
|
|
7
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Exception Class.
|
|
19
|
+
*
|
|
20
|
+
* @template TMessage The type of the message property of the Exception. Defaults to `string`.
|
|
21
|
+
* @template TCode The type of the code property of the Exception. Defaults to `ErrorCode`.
|
|
22
|
+
*
|
|
23
|
+
* @extends {Error}
|
|
24
|
+
* @implements {ExceptionOptions<TCode>}
|
|
25
|
+
*/
|
|
8
26
|
declare class Exception<TMessage = string, TCode = ErrorCode> extends Error implements ExceptionOptions<TCode> {
|
|
9
27
|
message: TMessage;
|
|
10
28
|
status: number | undefined;
|
|
11
29
|
name: string;
|
|
12
30
|
typename: 'Exception';
|
|
13
31
|
code: TCode;
|
|
32
|
+
/**
|
|
33
|
+
* Constructs a new Exception instance.
|
|
34
|
+
*
|
|
35
|
+
* @param message The message describing the exception.
|
|
36
|
+
* @param options Additional options for the exception.
|
|
37
|
+
*/
|
|
14
38
|
constructor(message: TMessage, options: ExceptionOptions<TCode>);
|
|
39
|
+
/**
|
|
40
|
+
* Determines if the provided error is an instance of the Exception class.
|
|
41
|
+
*
|
|
42
|
+
* @template TMessage The type of the message property of the Exception.
|
|
43
|
+
* @template TCode The type of the code property of the Exception.
|
|
44
|
+
*
|
|
45
|
+
* @param error The error to check.
|
|
46
|
+
* @returns `true` if the error is an instance of Exception or has a `typename` property equal to 'Exception', `false` otherwise.
|
|
47
|
+
*/
|
|
15
48
|
static isException<TMessage = string, TCode = ErrorCode>(error: any): error is Exception<TMessage, TCode>;
|
|
49
|
+
/**
|
|
50
|
+
* Converts the instance to a JSON object.
|
|
51
|
+
*
|
|
52
|
+
* @returns A JSON representation of the instance, including the message property.
|
|
53
|
+
*/
|
|
54
|
+
toJSON(): this & {
|
|
55
|
+
message: TMessage;
|
|
56
|
+
cause: unknown;
|
|
57
|
+
};
|
|
16
58
|
}
|
|
17
59
|
|
|
18
60
|
export { Exception, type ExceptionOptions };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,18 +1,60 @@
|
|
|
1
1
|
import { ErrorCode } from './code.js';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Interface representing the options for an Exception.
|
|
5
|
+
*
|
|
6
|
+
* @template TCode - The type of the error code.
|
|
7
|
+
* @extends ErrorOptions
|
|
8
|
+
*/
|
|
3
9
|
interface ExceptionOptions<TCode = ErrorCode> extends ErrorOptions {
|
|
10
|
+
/** The error code associated with the Exception. */
|
|
4
11
|
code: TCode;
|
|
12
|
+
/** The name of the Exception. */
|
|
5
13
|
name?: string;
|
|
14
|
+
/** The HTTP status code associated with the Exception. */
|
|
6
15
|
status?: number;
|
|
7
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Exception Class.
|
|
19
|
+
*
|
|
20
|
+
* @template TMessage The type of the message property of the Exception. Defaults to `string`.
|
|
21
|
+
* @template TCode The type of the code property of the Exception. Defaults to `ErrorCode`.
|
|
22
|
+
*
|
|
23
|
+
* @extends {Error}
|
|
24
|
+
* @implements {ExceptionOptions<TCode>}
|
|
25
|
+
*/
|
|
8
26
|
declare class Exception<TMessage = string, TCode = ErrorCode> extends Error implements ExceptionOptions<TCode> {
|
|
9
27
|
message: TMessage;
|
|
10
28
|
status: number | undefined;
|
|
11
29
|
name: string;
|
|
12
30
|
typename: 'Exception';
|
|
13
31
|
code: TCode;
|
|
32
|
+
/**
|
|
33
|
+
* Constructs a new Exception instance.
|
|
34
|
+
*
|
|
35
|
+
* @param message The message describing the exception.
|
|
36
|
+
* @param options Additional options for the exception.
|
|
37
|
+
*/
|
|
14
38
|
constructor(message: TMessage, options: ExceptionOptions<TCode>);
|
|
39
|
+
/**
|
|
40
|
+
* Determines if the provided error is an instance of the Exception class.
|
|
41
|
+
*
|
|
42
|
+
* @template TMessage The type of the message property of the Exception.
|
|
43
|
+
* @template TCode The type of the code property of the Exception.
|
|
44
|
+
*
|
|
45
|
+
* @param error The error to check.
|
|
46
|
+
* @returns `true` if the error is an instance of Exception or has a `typename` property equal to 'Exception', `false` otherwise.
|
|
47
|
+
*/
|
|
15
48
|
static isException<TMessage = string, TCode = ErrorCode>(error: any): error is Exception<TMessage, TCode>;
|
|
49
|
+
/**
|
|
50
|
+
* Converts the instance to a JSON object.
|
|
51
|
+
*
|
|
52
|
+
* @returns A JSON representation of the instance, including the message property.
|
|
53
|
+
*/
|
|
54
|
+
toJSON(): this & {
|
|
55
|
+
message: TMessage;
|
|
56
|
+
cause: unknown;
|
|
57
|
+
};
|
|
16
58
|
}
|
|
17
59
|
|
|
18
60
|
export { Exception, type ExceptionOptions };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var t=class o 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 o||typeof e=="object"&&"typename"in e&&e.typename==="Exception"}toJSON(){return {...this,message:this.message,cause:this.cause}}};exports.Exception=t;
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var t=class o 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 o||typeof e=="object"&&"typename"in e&&e.typename==="Exception"}toJSON(){return {...this,message:this.message,cause:this.cause}}};export{t as Exception};
|