grm-shared-library 1.0.17 → 1.0.19
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.
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.HttpExceptionFilter = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
const error_codes_enum_1 = require("../enums/error-codes.enum");
|
|
12
|
+
const custom_rpc_exception_1 = require("../custom-exception/custom-rpc.exception");
|
|
13
|
+
let HttpExceptionFilter = class HttpExceptionFilter {
|
|
14
|
+
catch(exception, host) {
|
|
15
|
+
const ctx = host.switchToHttp();
|
|
16
|
+
const response = ctx.getResponse();
|
|
17
|
+
const request = ctx.getRequest();
|
|
18
|
+
let status = common_1.HttpStatus.INTERNAL_SERVER_ERROR;
|
|
19
|
+
let errorResponse = {
|
|
20
|
+
message: 'Internal server error',
|
|
21
|
+
code: error_codes_enum_1.ErrorCodes.UNKNOWN_ERROR,
|
|
22
|
+
timestamp: new Date().toISOString()
|
|
23
|
+
};
|
|
24
|
+
if (exception instanceof common_1.HttpException) {
|
|
25
|
+
status = exception.getStatus();
|
|
26
|
+
errorResponse = exception.getResponse();
|
|
27
|
+
}
|
|
28
|
+
else if (exception instanceof custom_rpc_exception_1.CustomRpcException) {
|
|
29
|
+
errorResponse = exception.getErrorResponse();
|
|
30
|
+
}
|
|
31
|
+
response.status(status).json({
|
|
32
|
+
...errorResponse,
|
|
33
|
+
path: request.url,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
exports.HttpExceptionFilter = HttpExceptionFilter;
|
|
38
|
+
exports.HttpExceptionFilter = HttpExceptionFilter = __decorate([
|
|
39
|
+
(0, common_1.Catch)()
|
|
40
|
+
], HttpExceptionFilter);
|