@mondart/nestjs-common-module 1.1.28 → 1.1.30
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/dto/response/success-response.dto.d.ts +2 -2
- package/dist/dto/response/success-response.dto.js +5 -5
- package/dist/enums/shared-messages.enum.d.ts +1 -1
- package/dist/enums/shared-messages.enum.js +1 -1
- package/dist/filters/global-exception.filter.js +6 -5
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -2,8 +2,8 @@ export declare class BaseSuccessResponse<type> {
|
|
|
2
2
|
data: type;
|
|
3
3
|
metadata: object;
|
|
4
4
|
message: string;
|
|
5
|
-
|
|
5
|
+
status: number;
|
|
6
6
|
}
|
|
7
7
|
export declare class SuccessResponse<type> extends BaseSuccessResponse<type> {
|
|
8
|
-
constructor(data: type, message?: string,
|
|
8
|
+
constructor(data: type, message?: string, status?: number, metadata?: any);
|
|
9
9
|
}
|
|
@@ -11,7 +11,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.SuccessResponse = exports.BaseSuccessResponse = void 0;
|
|
13
13
|
const swagger_1 = require("@nestjs/swagger");
|
|
14
|
-
const
|
|
14
|
+
const enums_1 = require("../../enums");
|
|
15
15
|
class BaseSuccessResponse {
|
|
16
16
|
}
|
|
17
17
|
exports.BaseSuccessResponse = BaseSuccessResponse;
|
|
@@ -24,19 +24,19 @@ __decorate([
|
|
|
24
24
|
__metadata("design:type", Object)
|
|
25
25
|
], BaseSuccessResponse.prototype, "metadata", void 0);
|
|
26
26
|
__decorate([
|
|
27
|
-
(0, swagger_1.ApiProperty)({ type: String, default:
|
|
27
|
+
(0, swagger_1.ApiProperty)({ type: String, default: enums_1.SharedMessages.SUCCESSFUL }),
|
|
28
28
|
__metadata("design:type", String)
|
|
29
29
|
], BaseSuccessResponse.prototype, "message", void 0);
|
|
30
30
|
__decorate([
|
|
31
31
|
(0, swagger_1.ApiProperty)({ type: Number, default: 200 }),
|
|
32
32
|
__metadata("design:type", Number)
|
|
33
|
-
], BaseSuccessResponse.prototype, "
|
|
33
|
+
], BaseSuccessResponse.prototype, "status", void 0);
|
|
34
34
|
class SuccessResponse extends BaseSuccessResponse {
|
|
35
|
-
constructor(data, message = null,
|
|
35
|
+
constructor(data, message = null, status = 200, metadata = null) {
|
|
36
36
|
super();
|
|
37
37
|
this.data = data;
|
|
38
38
|
this.message = message;
|
|
39
|
-
this.
|
|
39
|
+
this.status = status;
|
|
40
40
|
this.metadata = metadata;
|
|
41
41
|
}
|
|
42
42
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export declare enum SharedMessages {
|
|
2
|
-
INTERNAL_SERVER_ERROR = "Internal Server Error.",
|
|
2
|
+
INTERNAL_SERVER_ERROR = "Internal Server Error {0}.",
|
|
3
3
|
NOT_IMPLEMENTED = "This feature has not been implemented yet.",
|
|
4
4
|
RECURSIVE_CHILD = "Some children IDs are invalid, the parent product can not be used in children, it is recursive.",
|
|
5
5
|
SUCCESSFUL = "Operation completed successfully.",
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.SharedMessages = void 0;
|
|
4
4
|
var SharedMessages;
|
|
5
5
|
(function (SharedMessages) {
|
|
6
|
-
SharedMessages["INTERNAL_SERVER_ERROR"] = "Internal Server Error.";
|
|
6
|
+
SharedMessages["INTERNAL_SERVER_ERROR"] = "Internal Server Error {0}.";
|
|
7
7
|
SharedMessages["NOT_IMPLEMENTED"] = "This feature has not been implemented yet.";
|
|
8
8
|
SharedMessages["RECURSIVE_CHILD"] = "Some children IDs are invalid, the parent product can not be used in children, it is recursive.";
|
|
9
9
|
SharedMessages["SUCCESSFUL"] = "Operation completed successfully.";
|
|
@@ -15,6 +15,7 @@ const config_1 = require("@nestjs/config");
|
|
|
15
15
|
const rxjs_1 = require("rxjs");
|
|
16
16
|
const dto_1 = require("../dto");
|
|
17
17
|
const enums_1 = require("../enums");
|
|
18
|
+
const helpers_1 = require("../helpers");
|
|
18
19
|
let GlobalExceptionFilter = class GlobalExceptionFilter {
|
|
19
20
|
constructor(configService) {
|
|
20
21
|
this.configService = configService;
|
|
@@ -25,8 +26,8 @@ let GlobalExceptionFilter = class GlobalExceptionFilter {
|
|
|
25
26
|
const type = host?.getType();
|
|
26
27
|
if (type === 'rpc') {
|
|
27
28
|
try {
|
|
28
|
-
logger.error(exception
|
|
29
|
-
return (0, rxjs_1.throwError)(() => exception
|
|
29
|
+
logger.error(exception ?? exception?.message);
|
|
30
|
+
return (0, rxjs_1.throwError)(() => exception ?? exception?.message);
|
|
30
31
|
}
|
|
31
32
|
catch (err) {
|
|
32
33
|
return (0, rxjs_1.throwError)(() => JSON.stringify(new dto_1.ErrorResponse(enums_1.SharedMessages.INTERNAL_SERVER_ERROR, common_1.HttpStatus.INTERNAL_SERVER_ERROR)));
|
|
@@ -34,9 +35,9 @@ let GlobalExceptionFilter = class GlobalExceptionFilter {
|
|
|
34
35
|
}
|
|
35
36
|
if (type === 'http') {
|
|
36
37
|
const response = context.getResponse();
|
|
37
|
-
const status = exception?.getStatus();
|
|
38
|
-
const result = exception.getResponse();
|
|
39
38
|
try {
|
|
39
|
+
const status = exception?.getStatus();
|
|
40
|
+
const result = exception.getResponse();
|
|
40
41
|
if (status === common_1.HttpStatus.UNPROCESSABLE_ENTITY) {
|
|
41
42
|
return response.status(status).json(result);
|
|
42
43
|
}
|
|
@@ -63,7 +64,7 @@ let GlobalExceptionFilter = class GlobalExceptionFilter {
|
|
|
63
64
|
catch (err) {
|
|
64
65
|
response
|
|
65
66
|
.status(common_1.HttpStatus.INTERNAL_SERVER_ERROR)
|
|
66
|
-
.json(new dto_1.ErrorResponse(enums_1.SharedMessages.INTERNAL_SERVER_ERROR, common_1.HttpStatus.INTERNAL_SERVER_ERROR));
|
|
67
|
+
.json(new dto_1.ErrorResponse(helpers_1.MessageFormatter.replace(enums_1.SharedMessages.INTERNAL_SERVER_ERROR, exception?.message), common_1.HttpStatus.INTERNAL_SERVER_ERROR));
|
|
67
68
|
}
|
|
68
69
|
}
|
|
69
70
|
}
|