@tsed/exceptions 7.18.1 → 7.18.3-rc.1
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.
|
@@ -2,11 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.HTTPException = exports.Exception = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
+
const core_1 = require("@tsed/core");
|
|
5
6
|
const change_case_1 = require("change-case");
|
|
6
7
|
const statuses_1 = tslib_1.__importDefault(require("statuses"));
|
|
7
|
-
function getStatusConstant(status) {
|
|
8
|
-
return status === 200 ? "SUCCESS" : (0, change_case_1.constantCase)(String((0, statuses_1.default)(status)));
|
|
9
|
-
}
|
|
10
8
|
class Exception extends Error {
|
|
11
9
|
/**
|
|
12
10
|
* Exception base name
|
|
@@ -43,7 +41,7 @@ class Exception extends Error {
|
|
|
43
41
|
super(message);
|
|
44
42
|
this.status = status;
|
|
45
43
|
this.message = message;
|
|
46
|
-
this.name = getStatusConstant(
|
|
44
|
+
this.name = this.#getStatusConstant();
|
|
47
45
|
this.setOrigin(origin);
|
|
48
46
|
}
|
|
49
47
|
setHeaders(headers) {
|
|
@@ -75,6 +73,14 @@ class Exception extends Error {
|
|
|
75
73
|
toString() {
|
|
76
74
|
return `${this.name}(${this.status}): ${this.message} `.trim();
|
|
77
75
|
}
|
|
76
|
+
#getStatusConstant() {
|
|
77
|
+
try {
|
|
78
|
+
return this.status === 200 ? "SUCCESS" : (0, change_case_1.constantCase)(String((0, statuses_1.default)(this.status)));
|
|
79
|
+
}
|
|
80
|
+
catch (er) {
|
|
81
|
+
return (0, change_case_1.constantCase)((0, core_1.nameOf)((0, core_1.classOf)(this)));
|
|
82
|
+
}
|
|
83
|
+
}
|
|
78
84
|
}
|
|
79
85
|
exports.Exception = Exception;
|
|
80
86
|
class HTTPException extends Exception {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Exception.js","sourceRoot":"","sources":["../../../src/core/Exception.ts"],"names":[],"mappings":";;;;AAAA,6CAAyC;AACzC,gEAAgC;AAEhC,
|
|
1
|
+
{"version":3,"file":"Exception.js","sourceRoot":"","sources":["../../../src/core/Exception.ts"],"names":[],"mappings":";;;;AAAA,qCAA2C;AAC3C,6CAAyC;AACzC,gEAAgC;AAEhC,MAAa,SAAU,SAAQ,KAAK;IAClC;;;OAGG;IACI,IAAI,GAAW,gBAAgB,CAAC;IACvC;;OAEG;IACI,OAAO,CAAS;IACvB;;;OAGG;IACI,IAAI,GAAW,gBAAgB,CAAC;IACvC;;OAEG;IACI,KAAK,CAAS;IACd,MAAM,CAAc;IAC3B;;OAEG;IACI,MAAM,CAAS;IACtB;;OAEG;IACI,IAAI,CAAM;IACjB;;OAEG;IACI,OAAO,GAAyB,EAAE,CAAC;IAI1C,YAAY,SAAiB,GAAG,EAAE,UAAkB,EAAE,EAAE,MAA6B;QACnF,KAAK,CAAC,OAAO,CAAC,CAAC;QAEf,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,kBAAkB,EAAE,CAAC;QAEtC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IACzB,CAAC;IAED,UAAU,CAAC,OAA6B;QACtC,IAAI,CAAC,OAAO,GAAG;YACb,GAAG,IAAI,CAAC,OAAO;YACf,GAAG,OAAO;SACX,CAAC;QAEF,OAAO,IAAI,CAAC;IACd,CAAC;IAED,SAAS,CAAC,GAAW,EAAE,KAAU;QAC/B,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;QAE1B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,SAAS,CAAC,MAA4B;QACpC,IAAI,MAAM,EAAE;YACV,IAAI,MAAM,YAAY,KAAK,EAAE;gBAC3B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;gBACrB,IAAI,CAAC,OAAO,GAAG,GAAG,IAAI,CAAC,OAAO,qBAAqB,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,CAAC;aACjF;iBAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;gBACrC,IAAI,CAAC,MAAM,GAAG,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC;gBAChC,IAAI,CAAC,OAAO,GAAG,GAAG,IAAI,CAAC,OAAO,qBAAqB,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,CAAC;aACjF;iBAAM;gBACL,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC;aACpB;SACF;IACH,CAAC;IAED,QAAQ;QACN,OAAO,GAAG,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,MAAM,MAAM,IAAI,CAAC,OAAO,GAAG,CAAC,IAAI,EAAE,CAAC;IACjE,CAAC;IAED,kBAAkB;QAChB,IAAI;YACF,OAAO,IAAI,CAAC,MAAM,KAAK,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAA,0BAAY,EAAC,MAAM,CAAC,IAAA,kBAAQ,EAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;SACtF;QAAC,OAAO,EAAE,EAAE;YACX,OAAO,IAAA,0BAAY,EAAC,IAAA,aAAM,EAAC,IAAA,cAAO,EAAC,IAAI,CAAC,CAAC,CAAC,CAAC;SAC5C;IACH,CAAC;CACF;AArFD,8BAqFC;AAED,MAAa,aAAc,SAAQ,SAAS;CAAG;AAA/C,sCAA+C","sourcesContent":["import {classOf, nameOf} from \"@tsed/core\";\nimport {constantCase} from \"change-case\";\nimport statuses from \"statuses\";\n\nexport class Exception extends Error {\n /**\n * Exception base name\n * @type {string}\n */\n public name: string = \"HTTP_EXCEPTION\";\n /**\n * Message of the exception\n */\n public message: string;\n /**\n * Exception type\n * @type {string}\n */\n public type: string = \"HTTP_EXCEPTION\";\n /**\n * Stack calling\n */\n public stack: string;\n public origin: Error & any;\n /**\n * HTTP Code Status\n */\n public status: number;\n /**\n *\n */\n public body: any;\n /**\n * Headers must be sent to the response\n */\n public headers: {[key: string]: any} = {};\n\n [key: string]: any;\n\n constructor(status: number = 500, message: string = \"\", origin?: Error | string | any) {\n super(message);\n\n this.status = status;\n this.message = message;\n this.name = this.#getStatusConstant();\n\n this.setOrigin(origin);\n }\n\n setHeaders(headers: {[key: string]: any}) {\n this.headers = {\n ...this.headers,\n ...headers\n };\n\n return this;\n }\n\n setHeader(key: string, value: any) {\n this.headers[key] = value;\n\n return this;\n }\n\n setOrigin(origin: Error | string | any) {\n if (origin) {\n if (origin instanceof Error) {\n this.origin = origin;\n this.message = `${this.message}, innerException: ${this.origin.message}`.trim();\n } else if (typeof origin === \"string\") {\n this.origin = new Error(origin);\n this.message = `${this.message}, innerException: ${this.origin.message}`.trim();\n } else {\n this.body = origin;\n }\n }\n }\n\n toString() {\n return `${this.name}(${this.status}): ${this.message} `.trim();\n }\n\n #getStatusConstant() {\n try {\n return this.status === 200 ? \"SUCCESS\" : constantCase(String(statuses(this.status)));\n } catch (er) {\n return constantCase(nameOf(classOf(this)));\n }\n }\n}\n\nexport class HTTPException extends Exception {}\n"]}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
+
import { classOf, nameOf } from "@tsed/core";
|
|
1
2
|
import { constantCase } from "change-case";
|
|
2
3
|
import statuses from "statuses";
|
|
3
|
-
function getStatusConstant(status) {
|
|
4
|
-
return status === 200 ? "SUCCESS" : constantCase(String(statuses(status)));
|
|
5
|
-
}
|
|
6
4
|
export class Exception extends Error {
|
|
7
5
|
/**
|
|
8
6
|
* Exception base name
|
|
@@ -39,7 +37,7 @@ export class Exception extends Error {
|
|
|
39
37
|
super(message);
|
|
40
38
|
this.status = status;
|
|
41
39
|
this.message = message;
|
|
42
|
-
this.name = getStatusConstant(
|
|
40
|
+
this.name = this.#getStatusConstant();
|
|
43
41
|
this.setOrigin(origin);
|
|
44
42
|
}
|
|
45
43
|
setHeaders(headers) {
|
|
@@ -71,6 +69,14 @@ export class Exception extends Error {
|
|
|
71
69
|
toString() {
|
|
72
70
|
return `${this.name}(${this.status}): ${this.message} `.trim();
|
|
73
71
|
}
|
|
72
|
+
#getStatusConstant() {
|
|
73
|
+
try {
|
|
74
|
+
return this.status === 200 ? "SUCCESS" : constantCase(String(statuses(this.status)));
|
|
75
|
+
}
|
|
76
|
+
catch (er) {
|
|
77
|
+
return constantCase(nameOf(classOf(this)));
|
|
78
|
+
}
|
|
79
|
+
}
|
|
74
80
|
}
|
|
75
81
|
export class HTTPException extends Exception {
|
|
76
82
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Exception.js","sourceRoot":"","sources":["../../../src/core/Exception.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"Exception.js","sourceRoot":"","sources":["../../../src/core/Exception.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAE,MAAM,EAAC,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAC,YAAY,EAAC,MAAM,aAAa,CAAC;AACzC,OAAO,QAAQ,MAAM,UAAU,CAAC;AAEhC,MAAM,OAAO,SAAU,SAAQ,KAAK;IAClC;;;OAGG;IACI,IAAI,GAAW,gBAAgB,CAAC;IACvC;;OAEG;IACI,OAAO,CAAS;IACvB;;;OAGG;IACI,IAAI,GAAW,gBAAgB,CAAC;IACvC;;OAEG;IACI,KAAK,CAAS;IACd,MAAM,CAAc;IAC3B;;OAEG;IACI,MAAM,CAAS;IACtB;;OAEG;IACI,IAAI,CAAM;IACjB;;OAEG;IACI,OAAO,GAAyB,EAAE,CAAC;IAI1C,YAAY,SAAiB,GAAG,EAAE,UAAkB,EAAE,EAAE,MAA6B;QACnF,KAAK,CAAC,OAAO,CAAC,CAAC;QAEf,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,OAA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CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;SACtF;QAAC,OAAO,EAAE,EAAE;YACX,OAAO,YAAY,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;SAC5C;IACH,CAAC;CACF;AAED,MAAM,OAAO,aAAc,SAAQ,SAAS;CAAG","sourcesContent":["import {classOf, nameOf} from \"@tsed/core\";\nimport {constantCase} from \"change-case\";\nimport statuses from \"statuses\";\n\nexport class Exception extends Error {\n /**\n * Exception base name\n * @type {string}\n */\n public name: string = \"HTTP_EXCEPTION\";\n /**\n * Message of the exception\n */\n public message: string;\n /**\n * Exception type\n * @type {string}\n */\n public type: string = \"HTTP_EXCEPTION\";\n /**\n * Stack calling\n */\n public stack: string;\n public origin: Error & any;\n /**\n * HTTP Code Status\n */\n public status: number;\n /**\n *\n */\n public body: any;\n /**\n * Headers must be sent to the response\n */\n public headers: {[key: string]: any} = {};\n\n [key: string]: any;\n\n constructor(status: number = 500, message: string = \"\", origin?: Error | string | any) {\n super(message);\n\n this.status = status;\n this.message = message;\n this.name = this.#getStatusConstant();\n\n this.setOrigin(origin);\n }\n\n setHeaders(headers: {[key: string]: any}) {\n this.headers = {\n ...this.headers,\n ...headers\n };\n\n return this;\n }\n\n setHeader(key: string, value: any) {\n this.headers[key] = value;\n\n return this;\n }\n\n setOrigin(origin: Error | string | any) {\n if (origin) {\n if (origin instanceof Error) {\n this.origin = origin;\n this.message = `${this.message}, innerException: ${this.origin.message}`.trim();\n } else if (typeof origin === \"string\") {\n this.origin = new Error(origin);\n this.message = `${this.message}, innerException: ${this.origin.message}`.trim();\n } else {\n this.body = origin;\n }\n }\n }\n\n toString() {\n return `${this.name}(${this.status}): ${this.message} `.trim();\n }\n\n #getStatusConstant() {\n try {\n return this.status === 200 ? \"SUCCESS\" : constantCase(String(statuses(this.status)));\n } catch (er) {\n return constantCase(nameOf(classOf(this)));\n }\n }\n}\n\nexport class HTTPException extends Exception {}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/exceptions",
|
|
3
|
-
"version": "7.18.1",
|
|
3
|
+
"version": "7.18.3-rc.1",
|
|
4
4
|
"description": "HTTP exceptions module for Ts.ED Framework and other pure Express application",
|
|
5
5
|
"private": false,
|
|
6
6
|
"source": "./src/index.ts",
|
|
@@ -35,5 +35,8 @@
|
|
|
35
35
|
},
|
|
36
36
|
"homepage": "https://github.com/tsedio/tsed/tree/production/packages/specs/exceptions",
|
|
37
37
|
"author": "Romain Lenzotti",
|
|
38
|
-
"license": "MIT"
|
|
38
|
+
"license": "MIT",
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"tag": "rc"
|
|
41
|
+
}
|
|
39
42
|
}
|