@node-c/api-http 1.0.0-alpha8 → 1.0.0-alpha9
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/dist/exceptionFilters/http.exceptionFilters.httpException.js.map +1 -1
- package/dist/interceptors/http.interceptors.error.d.ts +1 -1
- package/dist/interceptors/http.interceptors.error.js +7 -2
- package/dist/interceptors/http.interceptors.error.js.map +1 -1
- package/package.json +3 -3
- package/src/exceptionFilters/http.exceptionFilters.httpException.ts +0 -5
- package/src/interceptors/http.interceptors.error.ts +13 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.exceptionFilters.httpException.js","sourceRoot":"","sources":["../../src/exceptionFilters/http.exceptionFilters.httpException.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAsF;AAK/E,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;IAC9B,KAAK,CAAC,SAAwB,EAAE,IAAmB;QACjD,MAAM,GAAG,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;QAChC,MAAM,QAAQ,GAAG,GAAG,CAAC,WAAW,EAAY,CAAC;QAC7C,MAAM,MAAM,GAAG,SAAS,CAAC,SAAS,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"http.exceptionFilters.httpException.js","sourceRoot":"","sources":["../../src/exceptionFilters/http.exceptionFilters.httpException.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAsF;AAK/E,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;IAC9B,KAAK,CAAC,SAAwB,EAAE,IAAmB;QACjD,MAAM,GAAG,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;QAChC,MAAM,QAAQ,GAAG,GAAG,CAAC,WAAW,EAAY,CAAC;QAC7C,MAAM,MAAM,GAAG,SAAS,CAAC,SAAS,EAAE,CAAC;QACrC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC;YAC3B,UAAU,EAAE,MAAM;YAClB,OAAO,EAAE,SAAS,CAAC,OAAO;SAC3B,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AAVY,kDAAmB;8BAAnB,mBAAmB;IAD/B,IAAA,cAAK,EAAC,sBAAa,CAAC;GACR,mBAAmB,CAU/B"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CallHandler, ExecutionContext, NestInterceptor } from '@nestjs/common';
|
|
2
2
|
import { Observable } from 'rxjs';
|
|
3
3
|
export declare class HTTPErrorInterceptor implements NestInterceptor {
|
|
4
|
-
intercept(
|
|
4
|
+
intercept(context: ExecutionContext, next: CallHandler): Observable<unknown>;
|
|
5
5
|
}
|
|
@@ -12,7 +12,7 @@ const core_1 = require("@node-c/core");
|
|
|
12
12
|
const operators_1 = require("rxjs/operators");
|
|
13
13
|
const common_errors_1 = require("../common/definitions/common.errors");
|
|
14
14
|
let HTTPErrorInterceptor = class HTTPErrorInterceptor {
|
|
15
|
-
intercept(
|
|
15
|
+
intercept(context, next) {
|
|
16
16
|
return next.handle().pipe((0, operators_1.catchError)(error => {
|
|
17
17
|
console.error(error);
|
|
18
18
|
let message = 'An error has occurred.';
|
|
@@ -50,7 +50,12 @@ let HTTPErrorInterceptor = class HTTPErrorInterceptor {
|
|
|
50
50
|
message = error.message;
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
|
-
|
|
53
|
+
context
|
|
54
|
+
.switchToHttp()
|
|
55
|
+
.getResponse()
|
|
56
|
+
.status(status)
|
|
57
|
+
.json({ error: message instanceof Array ? message.join('\n') : message });
|
|
58
|
+
return [];
|
|
54
59
|
}));
|
|
55
60
|
}
|
|
56
61
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.interceptors.error.js","sourceRoot":"","sources":["../../src/interceptors/http.interceptors.error.ts"],"names":[],"mappings":";;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"http.interceptors.error.js","sourceRoot":"","sources":["../../src/interceptors/http.interceptors.error.ts"],"names":[],"mappings":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G,QAAQ,CAAC,OAAO,CAAC;gBAC7B,CAAC;YACH,CAAC;iBAAM,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;gBAClC,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC;oBAClB,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;gBAC1B,CAAC;YACH,CAAC;YAED,OAAO;iBACJ,YAAY,EAAE;iBACd,WAAW,EAAE;iBACb,MAAM,CAAC,MAAM,CAAC;iBACd,IAAI,CAAC,EAAE,KAAK,EAAE,OAAO,YAAY,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;YAC5E,OAAO,EAAE,CAAC;QAIZ,CAAC,CAAC,CACH,CAAC;IACJ,CAAC;CACF,CAAA;AAhDY,oDAAoB;+BAApB,oBAAoB;IADhC,IAAA,mBAAU,GAAE;GACA,oBAAoB,CAgDhC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@node-c/api-http",
|
|
3
|
-
"version": "1.0.0-
|
|
3
|
+
"version": "1.0.0-alpha9",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"@types/express": "^5.0.0"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
|
-
"@node-c/core": "^1.0.0-
|
|
27
|
-
"@node-c/domain-iam": "^1.0.0-
|
|
26
|
+
"@node-c/core": "^1.0.0-alpha9",
|
|
27
|
+
"@node-c/domain-iam": "^1.0.0-alpha9"
|
|
28
28
|
}
|
|
29
29
|
}
|
|
@@ -8,11 +8,6 @@ export class HttpExceptionFilter implements ExceptionFilter {
|
|
|
8
8
|
const ctx = host.switchToHttp();
|
|
9
9
|
const response = ctx.getResponse<Response>();
|
|
10
10
|
const status = exception.getStatus();
|
|
11
|
-
// else if (error instanceof BadRequestException) {
|
|
12
|
-
// const { statusCode, message: errorText } = error.getResponse() as unknown
|
|
13
|
-
// status = statusCode
|
|
14
|
-
// message = errorText || message
|
|
15
|
-
// }
|
|
16
11
|
response.status(status).json({
|
|
17
12
|
statusCode: status,
|
|
18
13
|
message: exception.message
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CallHandler, ExecutionContext,
|
|
1
|
+
import { CallHandler, ExecutionContext, Injectable, NestInterceptor } from '@nestjs/common';
|
|
2
2
|
|
|
3
3
|
import { ApplicationError } from '@node-c/core';
|
|
4
4
|
|
|
@@ -9,11 +9,11 @@ import { ServerError } from '../common/definitions/common.errors';
|
|
|
9
9
|
|
|
10
10
|
@Injectable()
|
|
11
11
|
export class HTTPErrorInterceptor implements NestInterceptor {
|
|
12
|
-
intercept(
|
|
12
|
+
intercept(context: ExecutionContext, next: CallHandler): Observable<unknown> {
|
|
13
13
|
return next.handle().pipe(
|
|
14
14
|
catchError(error => {
|
|
15
15
|
console.error(error);
|
|
16
|
-
let message = 'An error has occurred.';
|
|
16
|
+
let message: string | string[] = 'An error has occurred.';
|
|
17
17
|
let status = 500;
|
|
18
18
|
if (error instanceof ApplicationError || error instanceof ServerError) {
|
|
19
19
|
if (error.message) {
|
|
@@ -43,7 +43,16 @@ export class HTTPErrorInterceptor implements NestInterceptor {
|
|
|
43
43
|
message = error.message;
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
|
-
|
|
46
|
+
// TODO: fix this, as we're still getting error 500 when throwing the exception
|
|
47
|
+
context
|
|
48
|
+
.switchToHttp()
|
|
49
|
+
.getResponse()
|
|
50
|
+
.status(status)
|
|
51
|
+
.json({ error: message instanceof Array ? message.join('\n') : message });
|
|
52
|
+
return [];
|
|
53
|
+
// return throwError(
|
|
54
|
+
// () => new HttpException({ error: message instanceof Array ? message.join('\n') : message }, status)
|
|
55
|
+
// );
|
|
47
56
|
})
|
|
48
57
|
);
|
|
49
58
|
}
|