@tsed/platform-exceptions 7.0.0-beta.12 → 7.0.0-beta.13

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/jest.config.js ADDED
@@ -0,0 +1,14 @@
1
+ // For a detailed explanation regarding each configuration property, visit:
2
+ // https://jestjs.io/docs/en/configuration.html
3
+
4
+ module.exports = {
5
+ ...require("@tsed/jest-config")(__dirname, "platform-exceptions"),
6
+ coverageThreshold: {
7
+ global: {
8
+ statements: 100,
9
+ branches: 94.73,
10
+ functions: 100,
11
+ lines: 100
12
+ }
13
+ }
14
+ };
@@ -18,9 +18,8 @@ let ErrorFilter = class ErrorFilter {
18
18
  .body(env === core_1.Env.PROD ? "InternalServerError" : err);
19
19
  }
20
20
  mapError(error, env) {
21
- var _a;
22
21
  return {
23
- name: ((_a = error.origin) === null || _a === void 0 ? void 0 : _a.name) || error.name,
22
+ name: error.origin?.name || error.name,
24
23
  message: error.message,
25
24
  status: error.status || 500,
26
25
  errors: this.getErrors(error),
@@ -1 +1 @@
1
- {"version":3,"file":"ErrorFilter.js","sourceRoot":"","sources":["../../../src/components/ErrorFilter.ts"],"names":[],"mappings":";;;;AAAA,qCAA+B;AAE/B,+CAA0C;AAI1C,IAAa,WAAW,GAAxB,MAAa,WAAW;IACtB,KAAK,CAAC,KAAU,EAAE,GAAgB;QAChC,MAAM,EAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAC,GAAG,GAAG,CAAC;QACpC,MAAM,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QAEtC,MAAM,CAAC,KAAK,CAAC;YACX,KAAK,EAAE,EAAC,GAAG,GAAG,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAC;SACpC,CAAC,CAAC;QAEH,QAAQ;aACL,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;aAClC,MAAM,CAAC,GAAG,CAAC,MAA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AAC,KAAK,CAAC;GACA,WAAW,CAwCvB;AAxCY,kCAAW","sourcesContent":["import {Env} from \"@tsed/core\";\nimport {BaseContext} from \"@tsed/di\";\nimport {Catch} from \"../decorators/catch\";\nimport type {ExceptionFilterMethods} from \"../interfaces/ExceptionFilterMethods\";\n\n@Catch(Error)\nexport class ErrorFilter implements ExceptionFilterMethods {\n catch(error: any, ctx: BaseContext): void {\n const {response, logger, env} = ctx;\n const err = this.mapError(error, env);\n\n logger.error({\n error: {...err, stack: error.stack}\n });\n\n response\n .setHeaders(this.getHeaders(error))\n .status(err.status)\n .contentType(\"application/json\")\n .body(env === Env.PROD ? \"InternalServerError\" : err);\n }\n\n mapError(error: any, env?: Env) {\n return {\n name: error.origin?.name || error.name,\n message: error.message,\n status: error.status || 500,\n errors: this.getErrors(error),\n stack: env === Env.DEV ? error.stack : undefined\n };\n }\n\n protected getErrors(error: any) {\n return [error, error.origin].filter(Boolean).reduce((errs, {errors}: any) => {\n return errs.concat(errors).filter(Boolean);\n }, []);\n }\n\n protected getHeaders(error: any) {\n return [error, error.origin].filter(Boolean).reduce((obj, {headers}: any) => {\n return {\n ...obj,\n ...(headers || {})\n };\n }, {});\n }\n}\n"]}
1
+ {"version":3,"file":"ErrorFilter.js","sourceRoot":"","sources":["../../../src/components/ErrorFilter.ts"],"names":[],"mappings":";;;;AAAA,qCAA+B;AAE/B,+CAA0C;AAI1C,IAAa,WAAW,GAAxB,MAAa,WAAW;IACtB,KAAK,CAAC,KAAU,EAAE,GAAgB;QAChC,MAAM,EAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAC,GAAG,GAAG,CAAC;QACpC,MAAM,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QAEtC,MAAM,CAAC,KAAK,CAAC;YACX,KAAK,EAAE,EAAC,GAAG,GAAG,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAC;SACpC,CAAC,CAAC;QAEH,QAAQ;aACL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E,EAAE,CAAC,CAAC;IACT,CAAC;CACF,CAAA;AAxCY,WAAW;IADvB,IAAA,aAAK,EAAC,KAAK,CAAC;GACA,WAAW,CAwCvB;AAxCY,kCAAW","sourcesContent":["import {Env} from \"@tsed/core\";\nimport {BaseContext} from \"@tsed/di\";\nimport {Catch} from \"../decorators/catch\";\nimport type {ExceptionFilterMethods} from \"../interfaces/ExceptionFilterMethods\";\n\n@Catch(Error)\nexport class ErrorFilter implements ExceptionFilterMethods {\n catch(error: any, ctx: BaseContext): void {\n const {response, logger, env} = ctx;\n const err = this.mapError(error, env);\n\n logger.error({\n error: {...err, stack: error.stack}\n });\n\n response\n .setHeaders(this.getHeaders(error))\n .status(err.status)\n .contentType(\"application/json\")\n .body(env === Env.PROD ? \"InternalServerError\" : err);\n }\n\n mapError(error: any, env?: Env) {\n return {\n name: error.origin?.name || error.name,\n message: error.message,\n status: error.status || 500,\n errors: this.getErrors(error),\n stack: env === Env.DEV ? error.stack : undefined\n };\n }\n\n protected getErrors(error: any) {\n return [error, error.origin].filter(Boolean).reduce((errs, {errors}: any) => {\n return errs.concat(errors).filter(Boolean);\n }, []);\n }\n\n protected getHeaders(error: any) {\n return [error, error.origin].filter(Boolean).reduce((obj, {headers}: any) => {\n return {\n ...obj,\n ...(headers || {})\n };\n }, {});\n }\n}\n"]}
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ResourceNotFound = void 0;
4
4
  const exceptions_1 = require("@tsed/exceptions");
5
5
  class ResourceNotFound extends exceptions_1.NotFound {
6
+ url;
6
7
  constructor(url) {
7
8
  super(`Resource "${url}" not found`);
8
9
  this.url = url;
@@ -1 +1 @@
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","sourcesContent":["import {NotFound} from \"@tsed/exceptions\";\n\nexport class ResourceNotFound extends NotFound {\n readonly url: string;\n\n constructor(url: string) {\n super(`Resource \"${url}\" not found`);\n\n this.url = url;\n }\n}\n"]}
1
+ {"version":3,"file":"ResourceNotFound.js","sourceRoot":"","sources":["../../../src/errors/ResourceNotFound.ts"],"names":[],"mappings":";;;AAAA,iDAA0C;AAE1C,MAAa,gBAAiB,SAAQ,qBAAQ;IACnC,GAAG,CAAS;IAErB,YAAY,GAAW;QACrB,KAAK,CAAC,aAAa,GAAG,aAAa,CAAC,CAAC;QAErC,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACjB,CAAC;CACF;AARD,4CAQC","sourcesContent":["import {NotFound} from \"@tsed/exceptions\";\n\nexport class ResourceNotFound extends NotFound {\n readonly url: string;\n\n constructor(url: string) {\n super(`Resource \"${url}\" not found`);\n\n this.url = url;\n }\n}\n"]}
@@ -16,9 +16,8 @@ const ResourceNotFound_1 = require("../errors/ResourceNotFound");
16
16
  * @platform
17
17
  */
18
18
  let PlatformExceptions = class PlatformExceptions {
19
- constructor() {
20
- this.types = new Map();
21
- }
19
+ types = new Map();
20
+ injector;
22
21
  $onInit() {
23
22
  ExceptionFiltersContainer_1.ExceptionFiltersContainer.forEach((token, type) => {
24
23
  this.types.set(type, this.injector.get(token));
@@ -1 +1 @@
1
- {"version":3,"file":"PlatformExceptions.js","sourceRoot":"","sources":["../../../src/services/PlatformExceptions.ts"],"names":[],"mappings":";;;;AAAA,qCAAwD;AACxD,iCAA0E;AAC1E,2DAAsD;AACtD,mEAA8D;AAC9D,2EAAsE;AACtE,uEAAkE;AAClE,mFAAkG;AAClG,iEAA4D;AAG5D;;;;GAIG;AAIH,IAAa,kBAAkB,GAA/B,MAAa,kBAAkB;IAA/B;QACE,UAAK,GAAoD,IAAI,GAAG,EAAE,CAAC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,kBAAkB;IAH9B,IAAA,eAAU,EAAC;QACV,OAAO,EAAE,CAAC,yBAAW,EAAE,iCAAe,EAAE,yCAAmB,EAAE,qCAAiB,CAAC;KAChF,CAAC;GACW,kBAAkB,CAkC9B;AAlCY,gDAAkB","sourcesContent":["import {ancestorsOf, classOf, nameOf} from \"@tsed/core\";\nimport {BaseContext, Inject, Injectable, InjectorService} from \"@tsed/di\";\nimport {ErrorFilter} from \"../components/ErrorFilter\";\nimport {ExceptionFilter} from \"../components/ExceptionFilter\";\nimport {MongooseErrorFilter} from \"../components/MongooseErrorFilter\";\nimport {StringErrorFilter} from \"../components/StringErrorFilter\";\nimport {ExceptionFilterKey, ExceptionFiltersContainer} from \"../domain/ExceptionFiltersContainer\";\nimport {ResourceNotFound} from \"../errors/ResourceNotFound\";\nimport {ExceptionFilterMethods} from \"../interfaces/ExceptionFilterMethods\";\n\n/**\n * Catch all errors and return the json error with the right status code when it's possible.\n *\n * @platform\n */\n@Injectable({\n imports: [ErrorFilter, ExceptionFilter, MongooseErrorFilter, StringErrorFilter]\n})\nexport class PlatformExceptions {\n types: Map<ExceptionFilterKey, ExceptionFilterMethods> = new Map();\n\n @Inject()\n injector: InjectorService;\n\n $onInit() {\n ExceptionFiltersContainer.forEach((token, type) => {\n this.types.set(type, this.injector.get(token)!);\n });\n }\n\n catch(error: unknown, ctx: BaseContext) {\n const name = nameOf(classOf(error));\n\n if (name && this.types.has(name)) {\n return this.types.get(name)!.catch(error, ctx);\n }\n\n const target = ancestorsOf(error)\n .reverse()\n .find((target) => this.types.has(target));\n\n if (target) {\n return this.types.get(target)!.catch(error, ctx);\n }\n\n // default\n return this.types.get(Error)!.catch(error, ctx);\n }\n\n resourceNotFound(ctx: BaseContext) {\n return this.catch(new ResourceNotFound(ctx.request.url), ctx);\n }\n}\n"]}
1
+ {"version":3,"file":"PlatformExceptions.js","sourceRoot":"","sources":["../../../src/services/PlatformExceptions.ts"],"names":[],"mappings":";;;;AAAA,qCAAwD;AACxD,i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C,GAAgB;QAC/B,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,mCAAgB,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC;IAChE,CAAC;CACF,CAAA;AA9BC;IADC,IAAA,WAAM,GAAE;sCACC,oBAAe;oDAAC;AAJf,kBAAkB;IAH9B,IAAA,eAAU,EAAC;QACV,OAAO,EAAE,CAAC,yBAAW,EAAE,iCAAe,EAAE,yCAAmB,EAAE,qCAAiB,CAAC;KAChF,CAAC;GACW,kBAAkB,CAkC9B;AAlCY,gDAAkB","sourcesContent":["import {ancestorsOf, classOf, nameOf} from \"@tsed/core\";\nimport {BaseContext, Inject, Injectable, InjectorService} from \"@tsed/di\";\nimport {ErrorFilter} from \"../components/ErrorFilter\";\nimport {ExceptionFilter} from \"../components/ExceptionFilter\";\nimport {MongooseErrorFilter} from \"../components/MongooseErrorFilter\";\nimport {StringErrorFilter} from \"../components/StringErrorFilter\";\nimport {ExceptionFilterKey, ExceptionFiltersContainer} from \"../domain/ExceptionFiltersContainer\";\nimport {ResourceNotFound} from \"../errors/ResourceNotFound\";\nimport {ExceptionFilterMethods} from \"../interfaces/ExceptionFilterMethods\";\n\n/**\n * Catch all errors and return the json error with the right status code when it's possible.\n *\n * @platform\n */\n@Injectable({\n imports: [ErrorFilter, ExceptionFilter, MongooseErrorFilter, StringErrorFilter]\n})\nexport class PlatformExceptions {\n types: Map<ExceptionFilterKey, ExceptionFilterMethods> = new Map();\n\n @Inject()\n injector: InjectorService;\n\n $onInit() {\n ExceptionFiltersContainer.forEach((token, type) => {\n this.types.set(type, this.injector.get(token)!);\n });\n }\n\n catch(error: unknown, ctx: BaseContext) {\n const name = nameOf(classOf(error));\n\n if (name && this.types.has(name)) {\n return this.types.get(name)!.catch(error, ctx);\n }\n\n const target = ancestorsOf(error)\n .reverse()\n .find((target) => this.types.has(target));\n\n if (target) {\n return this.types.get(target)!.catch(error, ctx);\n }\n\n // default\n return this.types.get(Error)!.catch(error, ctx);\n }\n\n resourceNotFound(ctx: BaseContext) {\n return this.catch(new ResourceNotFound(ctx.request.url), ctx);\n }\n}\n"]}
@@ -15,9 +15,8 @@ let ErrorFilter = class ErrorFilter {
15
15
  .body(env === Env.PROD ? "InternalServerError" : err);
16
16
  }
17
17
  mapError(error, env) {
18
- var _a;
19
18
  return {
20
- name: ((_a = error.origin) === null || _a === void 0 ? void 0 : _a.name) || error.name,
19
+ name: error.origin?.name || error.name,
21
20
  message: error.message,
22
21
  status: error.status || 500,
23
22
  errors: this.getErrors(error),
@@ -1 +1 @@
1
- {"version":3,"file":"ErrorFilter.js","sourceRoot":"","sources":["../../../src/components/ErrorFilter.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,GAAG,EAAC,MAAM,YAAY,CAAC;AAE/B,OAAO,EAAC,KAAK,EAAC,MAAM,qBAAqB,CAAC;AAI1C,IAAa,WAAW,GAAxB,MAAa,WAAW;IACtB,KAAK,CAAC,KAAU,EAAE,GAAgB;QAChC,MAAM,EAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAC,GAAG,GAAG,CAAC;QACpC,MAAM,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QAEtC,MAAM,CAAC,KAAK,CAAC;YACX,KAAK,EAAE,EAAC,GAAG,GAAG,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAC;SACpC,CAAC,CAAC;QAEH,QAAQ;aACL,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;aAClC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC;aAClB,WAAW,CAAC,kBAAkB,CAAC;aAC/B,IAAI,CAAC,GAAG,KAAK,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IAC1D,CAAC;IAED,QAAQ,CAAC,KAAU,EAAE,GAAS;;QAC5B,OAAO;YACL,IAAI,EAAE,CAAA,MAAA,KAAK,CAAC,MAAM,0CAAE,IAAI,KAAI,KAAK,CAAC,IAAI;YACtC,OAAO,EAAE,KAAK,CAAC,OAAO;YACtB,MAAM,EAAE,KAAK,CAAC,MAAM,IAAI,GAAG;YAC3B,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;YAC7B,KAAK,EAAE,GAAG,KAAK,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS;SACjD,CAAC;IACJ,CAAC;IAES,SAAS,CAAC,KAAU;QAC5B,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAC,MAAM,EAAM,EAAE,EAAE;YAC1E,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,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;AAxCY,WAAW;IADvB,KAAK,CAAC,KAAK,CAAC;GACA,WAAW,CAwCvB;SAxCY,WAAW","sourcesContent":["import {Env} from \"@tsed/core\";\nimport {BaseContext} from \"@tsed/di\";\nimport {Catch} from \"../decorators/catch\";\nimport type {ExceptionFilterMethods} from \"../interfaces/ExceptionFilterMethods\";\n\n@Catch(Error)\nexport class ErrorFilter implements ExceptionFilterMethods {\n catch(error: any, ctx: BaseContext): void {\n const {response, logger, env} = ctx;\n const err = this.mapError(error, env);\n\n logger.error({\n error: {...err, stack: error.stack}\n });\n\n response\n .setHeaders(this.getHeaders(error))\n .status(err.status)\n .contentType(\"application/json\")\n .body(env === Env.PROD ? \"InternalServerError\" : err);\n }\n\n mapError(error: any, env?: Env) {\n return {\n name: error.origin?.name || error.name,\n message: error.message,\n status: error.status || 500,\n errors: this.getErrors(error),\n stack: env === Env.DEV ? error.stack : undefined\n };\n }\n\n protected getErrors(error: any) {\n return [error, error.origin].filter(Boolean).reduce((errs, {errors}: any) => {\n return errs.concat(errors).filter(Boolean);\n }, []);\n }\n\n protected getHeaders(error: any) {\n return [error, error.origin].filter(Boolean).reduce((obj, {headers}: any) => {\n return {\n ...obj,\n ...(headers || {})\n };\n }, {});\n }\n}\n"]}
1
+ {"version":3,"file":"ErrorFilter.js","sourceRoot":"","sources":["../../../src/components/ErrorFilter.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,GAAG,EAAC,MAAM,YAAY,CAAC;AAE/B,OAAO,EAAC,KAAK,EAAC,MAAM,qBAAqB,CAAC;AAI1C,IAAa,WAAW,GAAxB,MAAa,WAAW;IACtB,KAAK,CAAC,KAAU,EAAE,GAAgB;QAChC,MAAM,EAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAC,GAAG,GAAG,CAAC;QACpC,MAAM,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QAEtC,MAAM,CAAC,KAAK,CAAC;YACX,KAAK,EAAE,EAAC,GAAG,GAAG,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAC;SACpC,CAAC,CAAC;QAEH,QAAQ;aACL,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;aAClC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC;aAClB,WAAW,CAAC,kBAAkB,CAAC;aAC/B,IAAI,CAAC,GAAG,KAAK,GAAG,C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/di\";\nimport {Catch} from \"../decorators/catch\";\nimport type {ExceptionFilterMethods} from \"../interfaces/ExceptionFilterMethods\";\n\n@Catch(Error)\nexport class ErrorFilter implements ExceptionFilterMethods {\n catch(error: any, ctx: BaseContext): void {\n const {response, logger, env} = ctx;\n const err = this.mapError(error, env);\n\n logger.error({\n error: {...err, stack: error.stack}\n });\n\n response\n .setHeaders(this.getHeaders(error))\n .status(err.status)\n .contentType(\"application/json\")\n .body(env === Env.PROD ? \"InternalServerError\" : err);\n }\n\n mapError(error: any, env?: Env) {\n return {\n name: error.origin?.name || error.name,\n message: error.message,\n status: error.status || 500,\n errors: this.getErrors(error),\n stack: env === Env.DEV ? error.stack : undefined\n };\n }\n\n protected getErrors(error: any) {\n return [error, error.origin].filter(Boolean).reduce((errs, {errors}: any) => {\n return errs.concat(errors).filter(Boolean);\n }, []);\n }\n\n protected getHeaders(error: any) {\n return [error, error.origin].filter(Boolean).reduce((obj, {headers}: any) => {\n return {\n ...obj,\n ...(headers || {})\n };\n }, {});\n }\n}\n"]}
@@ -1,5 +1,6 @@
1
1
  import { NotFound } from "@tsed/exceptions";
2
2
  export class ResourceNotFound extends NotFound {
3
+ url;
3
4
  constructor(url) {
4
5
  super(`Resource "${url}" not found`);
5
6
  this.url = url;
@@ -1 +1 @@
1
- {"version":3,"file":"ResourceNotFound.js","sourceRoot":"","sources":["../../../src/errors/ResourceNotFound.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,kBAAkB,CAAC;AAE1C,MAAM,OAAO,gBAAiB,SAAQ,QAAQ;IAG5C,YAAY,GAAW;QACrB,KAAK,CAAC,aAAa,GAAG,aAAa,CAAC,CAAC;QAErC,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACjB,CAAC;CACF","sourcesContent":["import {NotFound} from \"@tsed/exceptions\";\n\nexport class ResourceNotFound extends NotFound {\n readonly url: string;\n\n constructor(url: string) {\n super(`Resource \"${url}\" not found`);\n\n this.url = url;\n }\n}\n"]}
1
+ {"version":3,"file":"ResourceNotFound.js","sourceRoot":"","sources":["../../../src/errors/ResourceNotFound.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,kBAAkB,CAAC;AAE1C,MAAM,OAAO,gBAAiB,SAAQ,QAAQ;IACnC,GAAG,CAAS;IAErB,YAAY,GAAW;QACrB,KAAK,CAAC,aAAa,GAAG,aAAa,CAAC,CAAC;QAErC,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACjB,CAAC;CACF","sourcesContent":["import {NotFound} from \"@tsed/exceptions\";\n\nexport class ResourceNotFound extends NotFound {\n readonly url: string;\n\n constructor(url: string) {\n super(`Resource \"${url}\" not found`);\n\n this.url = url;\n }\n}\n"]}
@@ -13,9 +13,8 @@ import { ResourceNotFound } from "../errors/ResourceNotFound.js";
13
13
  * @platform
14
14
  */
15
15
  let PlatformExceptions = class PlatformExceptions {
16
- constructor() {
17
- this.types = new Map();
18
- }
16
+ types = new Map();
17
+ injector;
19
18
  $onInit() {
20
19
  ExceptionFiltersContainer.forEach((token, type) => {
21
20
  this.types.set(type, this.injector.get(token));
@@ -1 +1 @@
1
- {"version":3,"file":"PlatformExceptions.js","sourceRoot":"","sources":["../../../src/services/PlatformExceptions.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,WAAW,EAAE,OAAO,EAAE,MAAM,EAAC,MAAM,YAAY,CAAC;AACxD,OAAO,EAAc,MAAM,EAAE,UAAU,EAAE,eAAe,EAAC,MAAM,UAAU,CAAC;AAC1E,OAAO,EAAC,WAAW,EAAC,MAAM,2BAA2B,CAAC;AACtD,OAAO,EAAC,eAAe,EAAC,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAC,mBAAmB,EAAC,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAAC,iBAAiB,EAAC,MAAM,iCAAiC,CAAC;AAClE,OAAO,EAAqB,yBAAyB,EAAC,MAAM,qCAAqC,CAAC;AAClG,OAAO,EAAC,gBAAg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C,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC;IAChE,CAAC;CACF,CAAA;AA9BC;IADC,MAAM,EAAE;8BACC,eAAe;oDAAC;AAJf,kBAAkB;IAH9B,UAAU,CAAC;QACV,OAAO,EAAE,CAAC,WAAW,EAAE,eAAe,EAAE,mBAAmB,EAAE,iBAAiB,CAAC;KAChF,CAAC;GACW,kBAAkB,CAkC9B;SAlCY,kBAAkB","sourcesContent":["import {ancestorsOf, classOf, nameOf} from \"@tsed/core\";\nimport {BaseContext, Inject, Injectable, InjectorService} from \"@tsed/di\";\nimport {ErrorFilter} from \"../components/ErrorFilter\";\nimport {ExceptionFilter} from \"../components/ExceptionFilter\";\nimport {MongooseErrorFilter} from \"../components/MongooseErrorFilter\";\nimport {StringErrorFilter} from \"../components/StringErrorFilter\";\nimport {ExceptionFilterKey, ExceptionFiltersContainer} from \"../domain/ExceptionFiltersContainer\";\nimport {ResourceNotFound} from \"../errors/ResourceNotFound\";\nimport {ExceptionFilterMethods} from \"../interfaces/ExceptionFilterMethods\";\n\n/**\n * Catch all errors and return the json error with the right status code when it's possible.\n *\n * @platform\n */\n@Injectable({\n imports: [ErrorFilter, ExceptionFilter, MongooseErrorFilter, StringErrorFilter]\n})\nexport class PlatformExceptions {\n types: Map<ExceptionFilterKey, ExceptionFilterMethods> = new Map();\n\n @Inject()\n injector: InjectorService;\n\n $onInit() {\n ExceptionFiltersContainer.forEach((token, type) => {\n this.types.set(type, this.injector.get(token)!);\n });\n }\n\n catch(error: unknown, ctx: BaseContext) {\n const name = nameOf(classOf(error));\n\n if (name && this.types.has(name)) {\n return this.types.get(name)!.catch(error, ctx);\n }\n\n const target = ancestorsOf(error)\n .reverse()\n .find((target) => this.types.has(target));\n\n if (target) {\n return this.types.get(target)!.catch(error, ctx);\n }\n\n // default\n return this.types.get(Error)!.catch(error, ctx);\n }\n\n resourceNotFound(ctx: BaseContext) {\n return this.catch(new ResourceNotFound(ctx.request.url), ctx);\n }\n}\n"]}
1
+ {"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AK,CAAC;aAC9B,OAAO,EAAE;aACT,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;QAE5C,IAAI,MAAM,EAAE;YACV,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAE,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;SAClD;QAED,UAAU;QACV,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAE,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAClD,CAAC;IAED,gBAAgB,CAAC,GAAgB;QAC/B,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,gBAAgB,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC;IAChE,CAAC;CACF,CAAA;AA9BC;IADC,MAAM,EAAE;8BACC,eAAe;oDAAC;AAJf,kBAAkB;IAH9B,UAAU,CAAC;QACV,OAAO,EAAE,CAAC,WAAW,EAAE,eAAe,EAAE,mBAAmB,EAAE,iBAAiB,CAAC;KAChF,CAAC;GACW,kBAAkB,CAkC9B;SAlCY,kBAAkB","sourcesContent":["import {ancestorsOf, classOf, nameOf} from \"@tsed/core\";\nimport {BaseContext, Inject, Injectable, InjectorService} from \"@tsed/di\";\nimport {ErrorFilter} from \"../components/ErrorFilter\";\nimport {ExceptionFilter} from \"../components/ExceptionFilter\";\nimport {MongooseErrorFilter} from \"../components/MongooseErrorFilter\";\nimport {StringErrorFilter} from \"../components/StringErrorFilter\";\nimport {ExceptionFilterKey, ExceptionFiltersContainer} from \"../domain/ExceptionFiltersContainer\";\nimport {ResourceNotFound} from \"../errors/ResourceNotFound\";\nimport {ExceptionFilterMethods} from \"../interfaces/ExceptionFilterMethods\";\n\n/**\n * Catch all errors and return the json error with the right status code when it's possible.\n *\n * @platform\n */\n@Injectable({\n imports: [ErrorFilter, ExceptionFilter, MongooseErrorFilter, StringErrorFilter]\n})\nexport class PlatformExceptions {\n types: Map<ExceptionFilterKey, ExceptionFilterMethods> = new Map();\n\n @Inject()\n injector: InjectorService;\n\n $onInit() {\n ExceptionFiltersContainer.forEach((token, type) => {\n this.types.set(type, this.injector.get(token)!);\n });\n }\n\n catch(error: unknown, ctx: BaseContext) {\n const name = nameOf(classOf(error));\n\n if (name && this.types.has(name)) {\n return this.types.get(name)!.catch(error, ctx);\n }\n\n const target = ancestorsOf(error)\n .reverse()\n .find((target) => this.types.has(target));\n\n if (target) {\n return this.types.get(target)!.catch(error, ctx);\n }\n\n // default\n return this.types.get(Error)!.catch(error, ctx);\n }\n\n resourceNotFound(ctx: BaseContext) {\n return this.catch(new ResourceNotFound(ctx.request.url), ctx);\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsed/platform-exceptions",
3
- "version": "7.0.0-beta.12",
3
+ "version": "7.0.0-beta.13",
4
4
  "description": "Platform exceptions module for Ts.ED Framework",
5
5
  "private": false,
6
6
  "source": "./src/index.ts",
@@ -17,22 +17,23 @@
17
17
  "build": "yarn barrels && yarn run build:esm && yarn run build:cjs",
18
18
  "build:cjs": "tsc --build tsconfig.compile.json",
19
19
  "build:esm": "tsc --build tsconfig.compile.esm.json",
20
- "barrels": "yarn barrelsby --delete -d ./src -e \"\\.spec\\.ts\" -e \"__mock__\" -e \".benchmark.ts\""
20
+ "barrels": "yarn barrelsby --delete -d ./src -e \"\\.spec\\.ts\" -e \"__mock__\" -e \".benchmark.ts\"",
21
+ "test": "cross-env NODE_ENV=test yarn jest --max-workers=2"
21
22
  },
22
23
  "dependencies": {
23
- "tslib": "2.3.1"
24
+ "tslib": "2.4.0"
24
25
  },
25
26
  "devDependencies": {
26
- "@tsed/core": "7.0.0-beta.12",
27
- "@tsed/di": "7.0.0-beta.12",
28
- "@tsed/exceptions": "7.0.0-beta.12",
29
- "@tsed/schema": "7.0.0-beta.12"
27
+ "@tsed/core": "7.0.0-beta.13",
28
+ "@tsed/di": "7.0.0-beta.13",
29
+ "@tsed/exceptions": "7.0.0-beta.13",
30
+ "@tsed/schema": "7.0.0-beta.13"
30
31
  },
31
32
  "peerDependencies": {
32
- "@tsed/core": "^7.0.0-beta.12",
33
- "@tsed/di": "^7.0.0-beta.12",
34
- "@tsed/exceptions": "^7.0.0-beta.12",
35
- "@tsed/schema": "^7.0.0-beta.12"
33
+ "@tsed/core": "^7.0.0-beta.13",
34
+ "@tsed/di": "^7.0.0-beta.13",
35
+ "@tsed/exceptions": "^7.0.0-beta.13",
36
+ "@tsed/schema": "^7.0.0-beta.13"
36
37
  },
37
38
  "peerDependenciesMeta": {
38
39
  "@tsed/core": {