@tsed/platform-exceptions 8.0.0-alpha.5 → 8.0.0-alpha.6

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.
Files changed (36) hide show
  1. package/package.json +13 -14
  2. package/lib/cjs/components/ErrorFilter.js +0 -44
  3. package/lib/cjs/components/ErrorFilter.js.map +0 -1
  4. package/lib/cjs/components/ExceptionFilter.js +0 -19
  5. package/lib/cjs/components/ExceptionFilter.js.map +0 -1
  6. package/lib/cjs/components/MongooseErrorFilter.js +0 -17
  7. package/lib/cjs/components/MongooseErrorFilter.js.map +0 -1
  8. package/lib/cjs/components/StringErrorFilter.js +0 -16
  9. package/lib/cjs/components/StringErrorFilter.js.map +0 -1
  10. package/lib/cjs/decorators/catch.js +0 -23
  11. package/lib/cjs/decorators/catch.js.map +0 -1
  12. package/lib/cjs/domain/ExceptionFiltersContainer.js +0 -16
  13. package/lib/cjs/domain/ExceptionFiltersContainer.js.map +0 -1
  14. package/lib/cjs/domain/ExceptionSchema.js +0 -36
  15. package/lib/cjs/domain/ExceptionSchema.js.map +0 -1
  16. package/lib/cjs/errors/ResourceNotFound.js +0 -12
  17. package/lib/cjs/errors/ResourceNotFound.js.map +0 -1
  18. package/lib/cjs/index.js +0 -17
  19. package/lib/cjs/index.js.map +0 -1
  20. package/lib/cjs/interfaces/ExceptionFilterMethods.js +0 -3
  21. package/lib/cjs/interfaces/ExceptionFilterMethods.js.map +0 -1
  22. package/lib/cjs/package.json +0 -3
  23. package/lib/cjs/services/PlatformExceptions.js +0 -55
  24. package/lib/cjs/services/PlatformExceptions.js.map +0 -1
  25. package/lib/esm/package.json +0 -3
  26. package/lib/types-esm/components/ErrorFilter.d.ts +0 -15
  27. package/lib/types-esm/components/ExceptionFilter.d.ts +0 -6
  28. package/lib/types-esm/components/MongooseErrorFilter.d.ts +0 -5
  29. package/lib/types-esm/components/StringErrorFilter.d.ts +0 -5
  30. package/lib/types-esm/decorators/catch.d.ts +0 -7
  31. package/lib/types-esm/domain/ExceptionFiltersContainer.d.ts +0 -14
  32. package/lib/types-esm/domain/ExceptionSchema.d.ts +0 -1
  33. package/lib/types-esm/errors/ResourceNotFound.d.ts +0 -5
  34. package/lib/types-esm/index.d.ts +0 -13
  35. package/lib/types-esm/interfaces/ExceptionFilterMethods.d.ts +0 -4
  36. package/lib/types-esm/services/PlatformExceptions.d.ts +0 -15
package/package.json CHANGED
@@ -1,17 +1,16 @@
1
1
  {
2
2
  "name": "@tsed/platform-exceptions",
3
3
  "description": "Platform exceptions module for Ts.ED Framework",
4
- "type": "commonjs",
5
- "version": "8.0.0-alpha.5",
4
+ "type": "module",
5
+ "version": "8.0.0-alpha.6",
6
6
  "source": "./src/index.ts",
7
- "main": "./lib/cjs/index.js",
7
+ "main": "./lib/esm/index.js",
8
8
  "module": "./lib/esm/index.js",
9
9
  "typings": "./lib/types/index.d.ts",
10
10
  "exports": {
11
11
  ".": {
12
12
  "types": "./lib/types/index.d.ts",
13
13
  "import": "./lib/esm/index.js",
14
- "require": "./lib/cjs/index.js",
15
14
  "default": "./lib/cjs/index.js"
16
15
  }
17
16
  },
@@ -26,21 +25,21 @@
26
25
  "tslib": "2.6.1"
27
26
  },
28
27
  "devDependencies": {
29
- "@tsed/barrels": "8.0.0-alpha.5",
30
- "@tsed/core": "8.0.0-alpha.5",
31
- "@tsed/di": "8.0.0-alpha.5",
32
- "@tsed/exceptions": "8.0.0-alpha.5",
33
- "@tsed/schema": "8.0.0-alpha.5",
34
- "@tsed/typescript": "8.0.0-alpha.5",
28
+ "@tsed/barrels": "8.0.0-alpha.6",
29
+ "@tsed/core": "8.0.0-alpha.6",
30
+ "@tsed/di": "8.0.0-alpha.6",
31
+ "@tsed/exceptions": "8.0.0-alpha.6",
32
+ "@tsed/schema": "8.0.0-alpha.6",
33
+ "@tsed/typescript": "8.0.0-alpha.6",
35
34
  "eslint": "^8.57.0",
36
35
  "typescript": "4.9.5",
37
36
  "vitest": "2.0.4"
38
37
  },
39
38
  "peerDependencies": {
40
- "@tsed/core": "8.0.0-alpha.5",
41
- "@tsed/di": "8.0.0-alpha.5",
42
- "@tsed/exceptions": "8.0.0-alpha.5",
43
- "@tsed/schema": "8.0.0-alpha.5"
39
+ "@tsed/core": "8.0.0-alpha.6",
40
+ "@tsed/di": "8.0.0-alpha.6",
41
+ "@tsed/exceptions": "8.0.0-alpha.6",
42
+ "@tsed/schema": "8.0.0-alpha.6"
44
43
  },
45
44
  "peerDependenciesMeta": {
46
45
  "@tsed/core": {
@@ -1,44 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ErrorFilter = void 0;
4
- const tslib_1 = require("tslib");
5
- const core_1 = require("@tsed/core");
6
- const catch_js_1 = require("../decorators/catch.js");
7
- let ErrorFilter = class ErrorFilter {
8
- catch(error, ctx) {
9
- const { response, logger, env } = ctx;
10
- const err = this.mapError(error, env);
11
- response
12
- .setHeaders(this.getHeaders(error))
13
- .status(err.status)
14
- .contentType("application/json")
15
- .body(env === core_1.Env.PROD ? "InternalServerError" : err);
16
- }
17
- mapError(error, env) {
18
- return {
19
- name: error.origin?.name || error.name || error.code,
20
- message: error.message,
21
- status: error.status || error.statusCode || 500,
22
- errors: this.getErrors(error),
23
- stack: env === core_1.Env.DEV ? error.stack : undefined
24
- };
25
- }
26
- getErrors(error) {
27
- return [error, error.origin].filter(Boolean).reduce((errs, { errors }) => {
28
- return errs.concat(errors).filter(Boolean);
29
- }, []);
30
- }
31
- getHeaders(error) {
32
- return [error, error.origin].filter(Boolean).reduce((obj, { headers }) => {
33
- return {
34
- ...obj,
35
- ...(headers || {})
36
- };
37
- }, {});
38
- }
39
- };
40
- ErrorFilter = tslib_1.__decorate([
41
- (0, catch_js_1.Catch)(Error)
42
- ], ErrorFilter);
43
- exports.ErrorFilter = ErrorFilter;
44
- //# sourceMappingURL=ErrorFilter.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ErrorFilter.js","sourceRoot":"","sources":["../../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,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAC7C,CAAC,EAAE,EAAE,CAAC,CAAC;IACT,CAAC;IAES,UAAU,CAAC,KAAU;QAC7B,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAC,OAAO,EAAM,EAAE,EAAE;YAC1E,OAAO;gBACL,GAAG,GAAG;gBACN,GAAG,CAAC,OAAO,IAAI,EAAE,CAAC;aACnB,CAAC;QACJ,CAAC,EAAE,EAAE,CAAC,CAAC;IACT,CAAC;CACF,CAAA;AApCY,WAAW;IADvB,IAAA,gBAAK,EAAC,KAAK,CAAC;GACA,WAAW,CAoCvB;AApCY,kCAAW"}
@@ -1,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ExceptionFilter = void 0;
4
- const tslib_1 = require("tslib");
5
- const exceptions_1 = require("@tsed/exceptions");
6
- const catch_js_1 = require("../decorators/catch.js");
7
- const ErrorFilter_js_1 = require("./ErrorFilter.js");
8
- let ExceptionFilter = class ExceptionFilter extends ErrorFilter_js_1.ErrorFilter {
9
- catch(error, ctx) {
10
- const { response, env } = ctx;
11
- const err = this.mapError(error, env);
12
- response.setHeaders(this.getHeaders(error)).contentType("application/json").status(error.status).body(err);
13
- }
14
- };
15
- ExceptionFilter = tslib_1.__decorate([
16
- (0, catch_js_1.Catch)(exceptions_1.Exception)
17
- ], ExceptionFilter);
18
- exports.ExceptionFilter = ExceptionFilter;
19
- //# sourceMappingURL=ExceptionFilter.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ExceptionFilter.js","sourceRoot":"","sources":["../../../src/components/ExceptionFilter.ts"],"names":[],"mappings":";;;;AACA,iDAA2C;AAC3C,qDAA6C;AAC7C,qDAA6C;AAGtC,IAAM,eAAe,GAArB,MAAM,eAAgB,SAAQ,4BAAW;IAC9C,KAAK,CAAC,KAAgB,EAAE,GAAgB;QACtC,MAAM,EAAC,QAAQ,EAAE,GAAG,EAAC,GAAG,GAAG,CAAC;QAC5B,MAAM,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QAEtC,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,WAAW,CAAC,kBAAkB,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC7G,CAAC;CACF,CAAA;AAPY,eAAe;IAD3B,IAAA,gBAAK,EAAC,sBAAS,CAAC;GACJ,eAAe,CAO3B;AAPY,0CAAe"}
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MongooseErrorFilter = void 0;
4
- const tslib_1 = require("tslib");
5
- const exceptions_1 = require("@tsed/exceptions");
6
- const catch_js_1 = require("../decorators/catch.js");
7
- const ErrorFilter_js_1 = require("./ErrorFilter.js");
8
- let MongooseErrorFilter = class MongooseErrorFilter extends ErrorFilter_js_1.ErrorFilter {
9
- catch(error, ctx) {
10
- return super.catch(new exceptions_1.BadRequest(error.message, error), ctx);
11
- }
12
- };
13
- MongooseErrorFilter = tslib_1.__decorate([
14
- (0, catch_js_1.Catch)("MongooseError", "MongoError")
15
- ], MongooseErrorFilter);
16
- exports.MongooseErrorFilter = MongooseErrorFilter;
17
- //# sourceMappingURL=MongooseErrorFilter.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"MongooseErrorFilter.js","sourceRoot":"","sources":["../../../src/components/MongooseErrorFilter.ts"],"names":[],"mappings":";;;;AACA,iDAA4C;AAC5C,qDAA6C;AAC7C,qDAA6C;AAGtC,IAAM,mBAAmB,GAAzB,MAAM,mBAAoB,SAAQ,4BAAW;IAClD,KAAK,CAAC,KAAY,EAAE,GAAgB;QAClC,OAAO,KAAK,CAAC,KAAK,CAAC,IAAI,uBAAU,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,EAAE,GAAG,CAAC,CAAC;IAChE,CAAC;CACF,CAAA;AAJY,mBAAmB;IAD/B,IAAA,gBAAK,EAAC,eAAe,EAAE,YAAY,CAAC;GACxB,mBAAmB,CAI/B;AAJY,kDAAmB"}
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.StringErrorFilter = void 0;
4
- const tslib_1 = require("tslib");
5
- const catch_js_1 = require("../decorators/catch.js");
6
- const toHTML = (message = "") => message.replace(/\n/gi, "<br />");
7
- let StringErrorFilter = class StringErrorFilter {
8
- catch(error, ctx) {
9
- ctx.response.status(404).body(toHTML(error));
10
- }
11
- };
12
- StringErrorFilter = tslib_1.__decorate([
13
- (0, catch_js_1.Catch)(String)
14
- ], StringErrorFilter);
15
- exports.StringErrorFilter = StringErrorFilter;
16
- //# sourceMappingURL=StringErrorFilter.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"StringErrorFilter.js","sourceRoot":"","sources":["../../../src/components/StringErrorFilter.ts"],"names":[],"mappings":";;;;AACA,qDAA6C;AAG7C,MAAM,MAAM,GAAG,CAAC,OAAO,GAAG,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;AAG5D,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAC5B,KAAK,CAAC,KAAa,EAAE,GAAgB;QACnC,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IAC/C,CAAC;CACF,CAAA;AAJY,iBAAiB;IAD7B,IAAA,gBAAK,EAAC,MAAM,CAAC;GACD,iBAAiB,CAI7B;AAJY,8CAAiB"}
@@ -1,23 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Catch = void 0;
4
- const di_1 = require("@tsed/di");
5
- const ExceptionFiltersContainer_js_1 = require("../domain/ExceptionFiltersContainer.js");
6
- /**
7
- * Register a new class to handle an specific exception.
8
- * @decorator
9
- * @param types
10
- */
11
- function Catch(...types) {
12
- return (target) => {
13
- types.forEach((type) => {
14
- (0, ExceptionFiltersContainer_js_1.registerExceptionType)(type, target);
15
- });
16
- (0, di_1.registerProvider)({
17
- provide: target,
18
- useClass: target
19
- });
20
- };
21
- }
22
- exports.Catch = Catch;
23
- //# sourceMappingURL=catch.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"catch.js","sourceRoot":"","sources":["../../../src/decorators/catch.ts"],"names":[],"mappings":";;;AACA,iCAA0C;AAC1C,yFAA6E;AAE7E;;;;GAIG;AACH,SAAgB,KAAK,CAAC,GAAG,KAAqC;IAC5D,OAAO,CAAC,MAAW,EAAE,EAAE;QACrB,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;YACrB,IAAA,oDAAqB,EAAC,IAAI,EAAE,MAAa,CAAC,CAAC;QAC7C,CAAC,CAAC,CAAC;QACH,IAAA,qBAAgB,EAAC;YACf,OAAO,EAAE,MAAM;YACf,QAAQ,EAAE,MAAM;SACjB,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AAVD,sBAUC"}
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.registerExceptionType = exports.ExceptionFiltersContainer = void 0;
4
- /**
5
- * @ignore
6
- */
7
- // tslint:disable-next-line:variable-name
8
- exports.ExceptionFiltersContainer = new Map();
9
- /**
10
- * @ignore
11
- */
12
- function registerExceptionType(type, token) {
13
- exports.ExceptionFiltersContainer.set(type, token);
14
- }
15
- exports.registerExceptionType = registerExceptionType;
16
- //# sourceMappingURL=ExceptionFiltersContainer.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ExceptionFiltersContainer.js","sourceRoot":"","sources":["../../../src/domain/ExceptionFiltersContainer.ts"],"names":[],"mappings":";;;AAMA;;GAEG;AACH,yCAAyC;AAC5B,QAAA,yBAAyB,GAAG,IAAI,GAAG,EAAoD,CAAC;AACrG;;GAEG;AACH,SAAgB,qBAAqB,CAAC,IAAwB,EAAE,KAAmC;IACjG,iCAAyB,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;AAC7C,CAAC;AAFD,sDAEC"}
@@ -1,36 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- const Exceptions = tslib_1.__importStar(require("@tsed/exceptions"));
5
- const exceptions_1 = require("@tsed/exceptions");
6
- const schema_1 = require("@tsed/schema");
7
- /**
8
- * @ignore
9
- */
10
- const ErrorSchema = (0, schema_1.object)({
11
- name: (0, schema_1.string)().required().description("The error name"),
12
- message: (0, schema_1.string)().required().description("An error message")
13
- })
14
- .label("GenericError")
15
- .unknown();
16
- (0, schema_1.from)(exceptions_1.Exception).properties({
17
- name: (0, schema_1.string)().required().description("The error name"),
18
- message: (0, schema_1.string)().required().description("An error message"),
19
- status: (0, schema_1.number)().required().description("The status code of the exception"),
20
- errors: (0, schema_1.array)().items(ErrorSchema).description("A list of related errors"),
21
- stack: (0, schema_1.string)().description("The stack trace (only in development mode)")
22
- });
23
- // Auto load models for all Exceptions
24
- Object.values(Exceptions).forEach((target) => {
25
- if (target !== exceptions_1.Exception && target.STATUS) {
26
- if (target.STATUS > 302) {
27
- const name = (0, schema_1.getStatusConstant)(target.STATUS);
28
- (0, schema_1.from)(target).properties({
29
- name: (0, schema_1.string)().required().example(name).default(name).description("The error name"),
30
- status: (0, schema_1.number)().required().example(target.STATUS).default(target.STATUS).description("The status code of the exception")
31
- });
32
- (0, schema_1.defineStatusModel)(target.STATUS, target);
33
- }
34
- }
35
- });
36
- //# sourceMappingURL=ExceptionSchema.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ExceptionSchema.js","sourceRoot":"","sources":["../../../src/domain/Except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AE,IAAA,eAAM,GAAE,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,WAAW,CAAC,gBAAgB,CAAC;gBACnF,MAAM,EAAE,IAAA,eAAM,GAAE,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,WAAW,CAAC,kCAAkC,CAAC;aAC1H,CAAC,CAAC;YAEH,IAAA,0BAAiB,EAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;SAC1C;KACF;AACH,CAAC,CAAC,CAAC"}
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ResourceNotFound = void 0;
4
- const exceptions_1 = require("@tsed/exceptions");
5
- class ResourceNotFound extends exceptions_1.NotFound {
6
- constructor(url) {
7
- super(`Resource "${url}" not found`);
8
- this.url = url;
9
- }
10
- }
11
- exports.ResourceNotFound = ResourceNotFound;
12
- //# sourceMappingURL=ResourceNotFound.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ResourceNotFound.js","sourceRoot":"","sources":["../../../src/errors/ResourceNotFound.ts"],"names":[],"mappings":";;;AAAA,iDAA0C;AAE1C,MAAa,gBAAiB,SAAQ,qBAAQ;IAG5C,YAAY,GAAW;QACrB,KAAK,CAAC,aAAa,GAAG,aAAa,CAAC,CAAC;QAErC,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACjB,CAAC;CACF;AARD,4CAQC"}
package/lib/cjs/index.js DELETED
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- /**
5
- * @file Automatically generated by @tsed/barrels.
6
- */
7
- tslib_1.__exportStar(require("./components/ErrorFilter.js"), exports);
8
- tslib_1.__exportStar(require("./components/ExceptionFilter.js"), exports);
9
- tslib_1.__exportStar(require("./components/MongooseErrorFilter.js"), exports);
10
- tslib_1.__exportStar(require("./components/StringErrorFilter.js"), exports);
11
- tslib_1.__exportStar(require("./decorators/catch.js"), exports);
12
- tslib_1.__exportStar(require("./domain/ExceptionFiltersContainer.js"), exports);
13
- tslib_1.__exportStar(require("./domain/ExceptionSchema.js"), exports);
14
- tslib_1.__exportStar(require("./errors/ResourceNotFound.js"), exports);
15
- tslib_1.__exportStar(require("./interfaces/ExceptionFilterMethods.js"), exports);
16
- tslib_1.__exportStar(require("./services/PlatformExceptions.js"), exports);
17
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,sEAA4C;AAC5C,0EAAgD;AAChD,8EAAoD;AACpD,4EAAkD;AAClD,gEAAsC;AACtC,gFAAsD;AACtD,sEAA4C;AAC5C,uEAA6C;AAC7C,iFAAuD;AACvD,2EAAiD"}
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=ExceptionFilterMethods.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ExceptionFilterMethods.js","sourceRoot":"","sources":["../../../src/interfaces/ExceptionFilterMethods.ts"],"names":[],"mappings":""}
@@ -1,3 +0,0 @@
1
- {
2
- "type": "commonjs"
3
- }
@@ -1,55 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PlatformExceptions = void 0;
4
- const tslib_1 = require("tslib");
5
- const core_1 = require("@tsed/core");
6
- const di_1 = require("@tsed/di");
7
- const ErrorFilter_js_1 = require("../components/ErrorFilter.js");
8
- const ExceptionFilter_js_1 = require("../components/ExceptionFilter.js");
9
- const MongooseErrorFilter_js_1 = require("../components/MongooseErrorFilter.js");
10
- const StringErrorFilter_js_1 = require("../components/StringErrorFilter.js");
11
- const ExceptionFiltersContainer_js_1 = require("../domain/ExceptionFiltersContainer.js");
12
- const ResourceNotFound_js_1 = require("../errors/ResourceNotFound.js");
13
- /**
14
- * Catch all errors and return the json error with the right status code when it's possible.
15
- *
16
- * @platform
17
- */
18
- let PlatformExceptions = class PlatformExceptions {
19
- constructor() {
20
- this.types = new Map();
21
- }
22
- $onInit() {
23
- ExceptionFiltersContainer_js_1.ExceptionFiltersContainer.forEach((token, type) => {
24
- this.types.set(type, this.injector.get(token));
25
- });
26
- }
27
- catch(error, ctx) {
28
- const name = (0, core_1.nameOf)((0, core_1.classOf)(error));
29
- if (name && this.types.has(name)) {
30
- return this.types.get(name).catch(error, ctx);
31
- }
32
- const target = (0, core_1.ancestorsOf)(error)
33
- .reverse()
34
- .find((target) => this.types.has(target));
35
- if (target) {
36
- return this.types.get(target).catch(error, ctx);
37
- }
38
- // default
39
- return this.types.get(Error).catch(error, ctx);
40
- }
41
- resourceNotFound(ctx) {
42
- return this.catch(new ResourceNotFound_js_1.ResourceNotFound(ctx.request.url), ctx);
43
- }
44
- };
45
- tslib_1.__decorate([
46
- (0, di_1.Inject)(),
47
- tslib_1.__metadata("design:type", di_1.InjectorService)
48
- ], PlatformExceptions.prototype, "injector", void 0);
49
- PlatformExceptions = tslib_1.__decorate([
50
- (0, di_1.Injectable)({
51
- imports: [ErrorFilter_js_1.ErrorFilter, ExceptionFilter_js_1.ExceptionFilter, MongooseErrorFilter_js_1.MongooseErrorFilter, StringErrorFilter_js_1.StringErrorFilter]
52
- })
53
- ], PlatformExceptions);
54
- exports.PlatformExceptions = PlatformExceptions;
55
- //# sourceMappingURL=PlatformExceptions.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PlatformExceptions.js","sourceRoot":"","sources":["../../../src/services/PlatformExceptions.ts"],"names":[],"mappings":";;;;AAAA,qCAAwD;AACxD,iCAAqF;AACrF,iEAAyD;AACzD,yEAAiE;AACjE,iFAAyE;AACzE,6EAAqE;AACrE,yFAAqG;AACrG,uEAA+D;AAG/D;;;;GAIG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AC,CAAC;IAChE,CAAC;CACF,CAAA;AA/BC;IAAC,IAAA,WAAM,GAAE;sCACC,oBAAe;oDAAC;AAJf,kBAAkB;IAH9B,IAAA,eAAU,EAAC;QACV,OAAO,EAAE,CAAC,4BAAW,EAAE,oCAAe,EAAE,4CAAmB,EAAE,wCAAiB,CAAC;KAChF,CAAC;GACW,kBAAkB,CAkC9B;AAlCY,gDAAkB"}
@@ -1,3 +0,0 @@
1
- {
2
- "type": "module"
3
- }
@@ -1,15 +0,0 @@
1
- import { Env } from "@tsed/core";
2
- import { BaseContext } from "@tsed/di";
3
- import type { ExceptionFilterMethods } from "../interfaces/ExceptionFilterMethods.js";
4
- export declare class ErrorFilter implements ExceptionFilterMethods {
5
- catch(error: any, ctx: BaseContext): void;
6
- mapError(error: any, env?: Env): {
7
- name: any;
8
- message: any;
9
- status: any;
10
- errors: any;
11
- stack: any;
12
- };
13
- protected getErrors(error: any): any;
14
- protected getHeaders(error: any): any;
15
- }
@@ -1,6 +0,0 @@
1
- import { BaseContext } from "@tsed/di";
2
- import { Exception } from "@tsed/exceptions";
3
- import { ErrorFilter } from "./ErrorFilter.js";
4
- export declare class ExceptionFilter extends ErrorFilter {
5
- catch(error: Exception, ctx: BaseContext): void;
6
- }
@@ -1,5 +0,0 @@
1
- import { BaseContext } from "@tsed/di";
2
- import { ErrorFilter } from "./ErrorFilter.js";
3
- export declare class MongooseErrorFilter extends ErrorFilter {
4
- catch(error: Error, ctx: BaseContext): void;
5
- }
@@ -1,5 +0,0 @@
1
- import { BaseContext } from "@tsed/di";
2
- import type { ExceptionFilterMethods } from "../interfaces/ExceptionFilterMethods.js";
3
- export declare class StringErrorFilter implements ExceptionFilterMethods {
4
- catch(error: string, ctx: BaseContext): void;
5
- }
@@ -1,7 +0,0 @@
1
- import { Type } from "@tsed/core";
2
- /**
3
- * Register a new class to handle an specific exception.
4
- * @decorator
5
- * @param types
6
- */
7
- export declare function Catch(...types: (Type<Error | any> | string)[]): (target: any) => void;
@@ -1,14 +0,0 @@
1
- import { Type } from "@tsed/core";
2
- import type { ExceptionFilterMethods } from "../interfaces/ExceptionFilterMethods.js";
3
- /**
4
- * @ignore
5
- */
6
- export type ExceptionFilterKey = Type<any> | Symbol | string;
7
- /**
8
- * @ignore
9
- */
10
- export declare const ExceptionFiltersContainer: Map<ExceptionFilterKey, Type<ExceptionFilterMethods<unknown>>>;
11
- /**
12
- * @ignore
13
- */
14
- export declare function registerExceptionType(type: ExceptionFilterKey, token: Type<ExceptionFilterMethods>): void;
@@ -1 +0,0 @@
1
- export {};
@@ -1,5 +0,0 @@
1
- import { NotFound } from "@tsed/exceptions";
2
- export declare class ResourceNotFound extends NotFound {
3
- readonly url: string;
4
- constructor(url: string);
5
- }
@@ -1,13 +0,0 @@
1
- /**
2
- * @file Automatically generated by @tsed/barrels.
3
- */
4
- export * from "./components/ErrorFilter.js";
5
- export * from "./components/ExceptionFilter.js";
6
- export * from "./components/MongooseErrorFilter.js";
7
- export * from "./components/StringErrorFilter.js";
8
- export * from "./decorators/catch.js";
9
- export * from "./domain/ExceptionFiltersContainer.js";
10
- export * from "./domain/ExceptionSchema.js";
11
- export * from "./errors/ResourceNotFound.js";
12
- export * from "./interfaces/ExceptionFilterMethods.js";
13
- export * from "./services/PlatformExceptions.js";
@@ -1,4 +0,0 @@
1
- import { DIContext } from "@tsed/di";
2
- export interface ExceptionFilterMethods<T = unknown> {
3
- catch(error: T, ctx: DIContext): void;
4
- }
@@ -1,15 +0,0 @@
1
- import { DIContext, InjectorService } from "@tsed/di";
2
- import { ExceptionFilterKey } from "../domain/ExceptionFiltersContainer.js";
3
- import { ExceptionFilterMethods } from "../interfaces/ExceptionFilterMethods.js";
4
- /**
5
- * Catch all errors and return the json error with the right status code when it's possible.
6
- *
7
- * @platform
8
- */
9
- export declare class PlatformExceptions {
10
- types: Map<ExceptionFilterKey, ExceptionFilterMethods>;
11
- injector: InjectorService;
12
- $onInit(): void;
13
- catch(error: unknown, ctx: DIContext): void;
14
- resourceNotFound(ctx: DIContext): void;
15
- }