@biorate/nestjs-tools 2.5.2 → 2.7.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.
|
@@ -12,46 +12,41 @@ const common_1 = require("@nestjs/common");
|
|
|
12
12
|
const errors_1 = require("../errors");
|
|
13
13
|
let AllExceptionsFilter = class AllExceptionsFilter {
|
|
14
14
|
catch(exception, host) {
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
this.type = host.getType();
|
|
16
|
+
this.exception = exception;
|
|
17
|
+
this.host = host;
|
|
18
|
+
const method = `_${this.type}`;
|
|
17
19
|
if (!this[method])
|
|
18
|
-
throw new errors_1.UnsupportedProtocolError(
|
|
19
|
-
this[method](
|
|
20
|
+
throw new errors_1.UnsupportedProtocolError(this.type);
|
|
21
|
+
this[method]();
|
|
20
22
|
}
|
|
21
|
-
_http(
|
|
22
|
-
const ctx = host.switchToHttp();
|
|
23
|
+
_http() {
|
|
24
|
+
const ctx = this.host.switchToHttp();
|
|
23
25
|
const response = ctx.getResponse();
|
|
24
26
|
const request = ctx.getRequest();
|
|
25
|
-
const meta = exception?.meta;
|
|
26
|
-
const status =
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
this.log(exception);
|
|
30
|
-
response.status(status).json({
|
|
27
|
+
const meta = this.exception?.meta;
|
|
28
|
+
const status = this.httpStatus;
|
|
29
|
+
this.log(this.exception);
|
|
30
|
+
response.status(status).json(this.format({
|
|
31
31
|
status,
|
|
32
|
-
code: this.code(exception),
|
|
33
|
-
hint: this.hint(exception),
|
|
34
32
|
path: request.url,
|
|
35
33
|
meta: meta?.meta,
|
|
36
|
-
});
|
|
34
|
+
}));
|
|
37
35
|
}
|
|
38
|
-
_ws(
|
|
39
|
-
const ctx = host.switchToWs();
|
|
36
|
+
_ws() {
|
|
37
|
+
const ctx = this.host.switchToWs();
|
|
40
38
|
const socket = ctx.getClient();
|
|
41
|
-
const meta = exception?.meta;
|
|
42
|
-
|
|
43
|
-
this.log(exception);
|
|
39
|
+
const meta = this.exception?.meta;
|
|
40
|
+
this.log(this.exception);
|
|
44
41
|
socket.send(JSON.stringify({
|
|
45
42
|
event: 'error',
|
|
46
|
-
data: {
|
|
47
|
-
status,
|
|
48
|
-
code: this.code(exception),
|
|
49
|
-
hint: this.hint(exception),
|
|
43
|
+
data: this.format({
|
|
44
|
+
status: this.wsStatus,
|
|
50
45
|
meta: meta?.meta,
|
|
51
|
-
},
|
|
46
|
+
}),
|
|
52
47
|
}));
|
|
53
48
|
}
|
|
54
|
-
_rpc(
|
|
49
|
+
_rpc() {
|
|
55
50
|
throw new errors_1.UnsupportedProtocolError('rpc');
|
|
56
51
|
}
|
|
57
52
|
code(exception) {
|
|
@@ -60,6 +55,21 @@ let AllExceptionsFilter = class AllExceptionsFilter {
|
|
|
60
55
|
hint(exception) {
|
|
61
56
|
return (exception?.getResponse?.()?.message ?? exception.message);
|
|
62
57
|
}
|
|
58
|
+
get httpStatus() {
|
|
59
|
+
return this.exception instanceof common_1.HttpException
|
|
60
|
+
? this.exception.getStatus()
|
|
61
|
+
: this.exception?.meta?.status ?? common_1.HttpStatus.INTERNAL_SERVER_ERROR;
|
|
62
|
+
}
|
|
63
|
+
get wsStatus() {
|
|
64
|
+
return this.exception?.meta?.status ?? common_1.HttpStatus.INTERNAL_SERVER_ERROR;
|
|
65
|
+
}
|
|
66
|
+
format(data) {
|
|
67
|
+
return {
|
|
68
|
+
code: this.code(this.exception),
|
|
69
|
+
hint: this.hint(this.exception),
|
|
70
|
+
...data,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
63
73
|
log(exception) {
|
|
64
74
|
if (exception instanceof axios_1.AxiosError)
|
|
65
75
|
console.error(new errors_1.AxiosRequestError(exception?.response?.data?.statusCode ?? exception.status, exception?.response?.data?.error ?? exception.code, exception?.response?.data?.message ?? exception.message).stack);
|
|
@@ -9,46 +9,41 @@ import { Catch, HttpException, HttpStatus, } from '@nestjs/common';
|
|
|
9
9
|
import { AxiosRequestError, UnsupportedProtocolError } from '../errors.js';
|
|
10
10
|
let AllExceptionsFilter = class AllExceptionsFilter {
|
|
11
11
|
catch(exception, host) {
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
this.type = host.getType();
|
|
13
|
+
this.exception = exception;
|
|
14
|
+
this.host = host;
|
|
15
|
+
const method = `_${this.type}`;
|
|
14
16
|
if (!this[method])
|
|
15
|
-
throw new UnsupportedProtocolError(
|
|
16
|
-
this[method](
|
|
17
|
+
throw new UnsupportedProtocolError(this.type);
|
|
18
|
+
this[method]();
|
|
17
19
|
}
|
|
18
|
-
_http(
|
|
19
|
-
const ctx = host.switchToHttp();
|
|
20
|
+
_http() {
|
|
21
|
+
const ctx = this.host.switchToHttp();
|
|
20
22
|
const response = ctx.getResponse();
|
|
21
23
|
const request = ctx.getRequest();
|
|
22
|
-
const meta = exception?.meta;
|
|
23
|
-
const status =
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
this.log(exception);
|
|
27
|
-
response.status(status).json({
|
|
24
|
+
const meta = this.exception?.meta;
|
|
25
|
+
const status = this.httpStatus;
|
|
26
|
+
this.log(this.exception);
|
|
27
|
+
response.status(status).json(this.format({
|
|
28
28
|
status,
|
|
29
|
-
code: this.code(exception),
|
|
30
|
-
hint: this.hint(exception),
|
|
31
29
|
path: request.url,
|
|
32
30
|
meta: meta?.meta,
|
|
33
|
-
});
|
|
31
|
+
}));
|
|
34
32
|
}
|
|
35
|
-
_ws(
|
|
36
|
-
const ctx = host.switchToWs();
|
|
33
|
+
_ws() {
|
|
34
|
+
const ctx = this.host.switchToWs();
|
|
37
35
|
const socket = ctx.getClient();
|
|
38
|
-
const meta = exception?.meta;
|
|
39
|
-
|
|
40
|
-
this.log(exception);
|
|
36
|
+
const meta = this.exception?.meta;
|
|
37
|
+
this.log(this.exception);
|
|
41
38
|
socket.send(JSON.stringify({
|
|
42
39
|
event: 'error',
|
|
43
|
-
data: {
|
|
44
|
-
status,
|
|
45
|
-
code: this.code(exception),
|
|
46
|
-
hint: this.hint(exception),
|
|
40
|
+
data: this.format({
|
|
41
|
+
status: this.wsStatus,
|
|
47
42
|
meta: meta?.meta,
|
|
48
|
-
},
|
|
43
|
+
}),
|
|
49
44
|
}));
|
|
50
45
|
}
|
|
51
|
-
_rpc(
|
|
46
|
+
_rpc() {
|
|
52
47
|
throw new UnsupportedProtocolError('rpc');
|
|
53
48
|
}
|
|
54
49
|
code(exception) {
|
|
@@ -57,6 +52,21 @@ let AllExceptionsFilter = class AllExceptionsFilter {
|
|
|
57
52
|
hint(exception) {
|
|
58
53
|
return (exception?.getResponse?.()?.message ?? exception.message);
|
|
59
54
|
}
|
|
55
|
+
get httpStatus() {
|
|
56
|
+
return this.exception instanceof HttpException
|
|
57
|
+
? this.exception.getStatus()
|
|
58
|
+
: this.exception?.meta?.status ?? HttpStatus.INTERNAL_SERVER_ERROR;
|
|
59
|
+
}
|
|
60
|
+
get wsStatus() {
|
|
61
|
+
return this.exception?.meta?.status ?? HttpStatus.INTERNAL_SERVER_ERROR;
|
|
62
|
+
}
|
|
63
|
+
format(data) {
|
|
64
|
+
return {
|
|
65
|
+
code: this.code(this.exception),
|
|
66
|
+
hint: this.hint(this.exception),
|
|
67
|
+
...data,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
60
70
|
log(exception) {
|
|
61
71
|
if (exception instanceof AxiosError)
|
|
62
72
|
console.error(new AxiosRequestError(exception?.response?.data?.statusCode ?? exception.status, exception?.response?.data?.error ?? exception.code, exception?.response?.data?.message ?? exception.message).stack);
|
|
@@ -1,10 +1,19 @@
|
|
|
1
|
-
import { ExceptionFilter, ArgumentsHost } from '@nestjs/common';
|
|
1
|
+
import { ExceptionFilter, ArgumentsHost, ContextType } from '@nestjs/common';
|
|
2
2
|
export declare class AllExceptionsFilter implements ExceptionFilter {
|
|
3
|
+
protected type: ContextType;
|
|
4
|
+
protected exception: Error;
|
|
5
|
+
protected host: ArgumentsHost;
|
|
3
6
|
catch(exception: Error, host: ArgumentsHost): void;
|
|
4
7
|
private _http;
|
|
5
8
|
private _ws;
|
|
6
9
|
private _rpc;
|
|
7
10
|
private code;
|
|
8
11
|
private hint;
|
|
12
|
+
protected get httpStatus(): any;
|
|
13
|
+
protected get wsStatus(): any;
|
|
14
|
+
protected format(data: Record<string, unknown>): {
|
|
15
|
+
code: string;
|
|
16
|
+
hint: string | [string];
|
|
17
|
+
};
|
|
9
18
|
protected log(exception: Error): void;
|
|
10
19
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@biorate/nestjs-tools",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.7.0",
|
|
4
4
|
"description": "NestJS tools",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"module": "./dist/esm/index.js",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"keywords": [],
|
|
46
46
|
"author": "llevkin",
|
|
47
47
|
"license": "MIT",
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "90bfe8f2c4e04c99bb273171a15a185b818d5104",
|
|
49
49
|
"peerDependencies": {
|
|
50
50
|
"@nestjs/common": ">=10.4.15",
|
|
51
51
|
"@nestjs/core": ">=10.4.15",
|