@tsed/platform-exceptions 8.0.0-rc.4 → 8.0.0-rc.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.
- package/lib/esm/decorators/catch.js +2 -5
- package/lib/esm/decorators/catch.js.map +1 -1
- package/lib/esm/services/PlatformExceptions.js +14 -23
- package/lib/esm/services/PlatformExceptions.js.map +1 -1
- package/lib/types/services/PlatformExceptions.d.ts +6 -7
- package/package.json +11 -11
- package/vitest.config.mts +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { injectable } from "@tsed/di";
|
|
2
2
|
import { registerExceptionType } from "../domain/ExceptionFiltersContainer.js";
|
|
3
3
|
/**
|
|
4
4
|
* Register a new class to handle an specific exception.
|
|
@@ -10,10 +10,7 @@ export function Catch(...types) {
|
|
|
10
10
|
types.forEach((type) => {
|
|
11
11
|
registerExceptionType(type, target);
|
|
12
12
|
});
|
|
13
|
-
|
|
14
|
-
provide: target,
|
|
15
|
-
useClass: target
|
|
16
|
-
});
|
|
13
|
+
injectable(target).class(target);
|
|
17
14
|
};
|
|
18
15
|
}
|
|
19
16
|
//# sourceMappingURL=catch.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"catch.js","sourceRoot":"","sources":["../../../src/decorators/catch.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"catch.js","sourceRoot":"","sources":["../../../src/decorators/catch.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,UAAU,EAAmB,MAAM,UAAU,CAAC;AAEtD,OAAO,EAAC,qBAAqB,EAAC,MAAM,wCAAwC,CAAC;AAE7E;;;;GAIG;AACH,MAAM,UAAU,KAAK,CAAC,GAAG,KAAqC;IAC5D,OAAO,CAAC,MAAW,EAAE,EAAE;QACrB,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;YACrB,qBAAqB,CAAC,IAAI,EAAE,MAAa,CAAC,CAAC;QAC7C,CAAC,CAAC,CAAC;QACH,UAAU,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IACnC,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { __decorate, __metadata } from "tslib";
|
|
2
1
|
import { ancestorsOf, classOf, nameOf } from "@tsed/core";
|
|
3
|
-
import {
|
|
2
|
+
import { inject, injectable } from "@tsed/di";
|
|
4
3
|
import { ErrorFilter } from "../components/ErrorFilter.js";
|
|
5
4
|
import { ExceptionFilter } from "../components/ExceptionFilter.js";
|
|
6
5
|
import { MongooseErrorFilter } from "../components/MongooseErrorFilter.js";
|
|
@@ -12,41 +11,33 @@ import { ResourceNotFound } from "../errors/ResourceNotFound.js";
|
|
|
12
11
|
*
|
|
13
12
|
* @platform
|
|
14
13
|
*/
|
|
15
|
-
|
|
14
|
+
export class PlatformExceptions {
|
|
16
15
|
constructor() {
|
|
17
16
|
this.types = new Map();
|
|
18
|
-
}
|
|
19
|
-
$onInit() {
|
|
20
17
|
ExceptionFiltersContainer.forEach((token, type) => {
|
|
21
|
-
this.types.set(type,
|
|
18
|
+
this.types.set(type, token);
|
|
22
19
|
});
|
|
23
20
|
}
|
|
24
21
|
catch(error, ctx) {
|
|
22
|
+
return this.resolve(error, ctx).catch(error, ctx);
|
|
23
|
+
}
|
|
24
|
+
resourceNotFound(ctx) {
|
|
25
|
+
return this.catch(new ResourceNotFound(ctx.request.url), ctx);
|
|
26
|
+
}
|
|
27
|
+
resolve(error, ctx) {
|
|
25
28
|
const name = nameOf(classOf(error));
|
|
26
29
|
if (name && this.types.has(name)) {
|
|
27
|
-
return this.types.get(name)
|
|
30
|
+
return inject(this.types.get(name));
|
|
28
31
|
}
|
|
29
32
|
const target = ancestorsOf(error)
|
|
30
33
|
.reverse()
|
|
31
34
|
.find((target) => this.types.has(target));
|
|
32
35
|
if (target) {
|
|
33
|
-
return this.types.get(target)
|
|
36
|
+
return inject(this.types.get(target));
|
|
34
37
|
}
|
|
35
38
|
// default
|
|
36
|
-
return this.types.get(Error)
|
|
37
|
-
}
|
|
38
|
-
resourceNotFound(ctx) {
|
|
39
|
-
return this.catch(new ResourceNotFound(ctx.request.url), ctx);
|
|
39
|
+
return inject(this.types.get(Error));
|
|
40
40
|
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
Inject(),
|
|
44
|
-
__metadata("design:type", InjectorService)
|
|
45
|
-
], PlatformExceptions.prototype, "injector", void 0);
|
|
46
|
-
PlatformExceptions = __decorate([
|
|
47
|
-
Injectable({
|
|
48
|
-
imports: [ErrorFilter, ExceptionFilter, MongooseErrorFilter, StringErrorFilter]
|
|
49
|
-
})
|
|
50
|
-
], PlatformExceptions);
|
|
51
|
-
export { PlatformExceptions };
|
|
41
|
+
}
|
|
42
|
+
injectable(PlatformExceptions).imports([ErrorFilter, ExceptionFilter, MongooseErrorFilter, StringErrorFilter]);
|
|
52
43
|
//# sourceMappingURL=PlatformExceptions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformExceptions.js","sourceRoot":"","sources":["../../../src/services/PlatformExceptions.ts"],"names":[],"mappings":"
|
|
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,EAAY,MAAM,EAAE,UAAU,EAAqB,MAAM,UAAU,CAAC;AAE3E,OAAO,EAAC,WAAW,EAAC,MAAM,8BAA8B,CAAC;AACzD,OAAO,EAAC,eAAe,EAAC,MAAM,kCAAkC,CAAC;AACjE,OAAO,EAAC,mBAAmB,EAAC,MAAM,sCAAsC,CAAC;AACzE,OAAO,EAAC,iBAAiB,EAAC,MAAM,oCAAoC,CAAC;AACrE,OAAO,EAAqB,yBAAyB,EAAC,MAAM,wCAAwC,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ED,UAAU;QACV,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAE,CAAC,CAAC;IACxC,CAAC;CACF;AAED,UAAU,CAAC,kBAAkB,CAAC,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,eAAe,EAAE,mBAAmB,EAAE,iBAAiB,CAAC,CAAC,CAAC"}
|
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import { DIContext,
|
|
1
|
+
import { DIContext, type TokenProvider } from "@tsed/di";
|
|
2
2
|
import { ExceptionFilterKey } from "../domain/ExceptionFiltersContainer.js";
|
|
3
|
-
import { ExceptionFilterMethods } from "../interfaces/ExceptionFilterMethods.js";
|
|
4
3
|
/**
|
|
5
4
|
* Catch all errors and return the json error with the right status code when it's possible.
|
|
6
5
|
*
|
|
7
6
|
* @platform
|
|
8
7
|
*/
|
|
9
8
|
export declare class PlatformExceptions {
|
|
10
|
-
types: Map<ExceptionFilterKey,
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
types: Map<ExceptionFilterKey, TokenProvider>;
|
|
10
|
+
constructor();
|
|
11
|
+
catch(error: unknown, ctx: DIContext): any;
|
|
12
|
+
resourceNotFound(ctx: DIContext): any;
|
|
13
|
+
protected resolve(error: any, ctx: DIContext): any;
|
|
15
14
|
}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@tsed/platform-exceptions",
|
|
3
3
|
"description": "Platform exceptions module for Ts.ED Framework",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "8.0.0-rc.
|
|
5
|
+
"version": "8.0.0-rc.6",
|
|
6
6
|
"source": "./src/index.ts",
|
|
7
7
|
"main": "./lib/esm/index.js",
|
|
8
8
|
"module": "./lib/esm/index.js",
|
|
@@ -24,22 +24,22 @@
|
|
|
24
24
|
"tslib": "2.7.0"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@tsed/barrels": "8.0.0-rc.
|
|
28
|
-
"@tsed/core": "8.0.0-rc.
|
|
29
|
-
"@tsed/di": "8.0.0-rc.
|
|
30
|
-
"@tsed/exceptions": "8.0.0-rc.
|
|
31
|
-
"@tsed/schema": "8.0.0-rc.
|
|
32
|
-
"@tsed/typescript": "8.0.0-rc.
|
|
27
|
+
"@tsed/barrels": "8.0.0-rc.6",
|
|
28
|
+
"@tsed/core": "8.0.0-rc.6",
|
|
29
|
+
"@tsed/di": "8.0.0-rc.6",
|
|
30
|
+
"@tsed/exceptions": "8.0.0-rc.6",
|
|
31
|
+
"@tsed/schema": "8.0.0-rc.6",
|
|
32
|
+
"@tsed/typescript": "8.0.0-rc.6",
|
|
33
33
|
"ajv": "^8.17.1",
|
|
34
34
|
"eslint": "9.12.0",
|
|
35
35
|
"typescript": "5.4.5",
|
|
36
36
|
"vitest": "2.1.2"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
|
-
"@tsed/core": "8.0.0-rc.
|
|
40
|
-
"@tsed/di": "8.0.0-rc.
|
|
41
|
-
"@tsed/exceptions": "8.0.0-rc.
|
|
42
|
-
"@tsed/schema": "8.0.0-rc.
|
|
39
|
+
"@tsed/core": "8.0.0-rc.6",
|
|
40
|
+
"@tsed/di": "8.0.0-rc.6",
|
|
41
|
+
"@tsed/exceptions": "8.0.0-rc.6",
|
|
42
|
+
"@tsed/schema": "8.0.0-rc.6"
|
|
43
43
|
},
|
|
44
44
|
"peerDependenciesMeta": {
|
|
45
45
|
"@tsed/core": {
|