@mondart/nestjs-common-module 1.1.63 → 1.1.65
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/decorators/validations/index.d.ts +1 -0
- package/dist/decorators/validations/index.js +1 -0
- package/dist/decorators/validations/is-one-of-property.decorator.d.ts +2 -0
- package/dist/decorators/validations/is-one-of-property.decorator.js +24 -0
- package/dist/filters/global-exception.filter.js +38 -23
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -17,3 +17,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./default"), exports);
|
|
18
18
|
__exportStar(require("./is-id.decorator"), exports);
|
|
19
19
|
__exportStar(require("./is-not-empty-string.decorator"), exports);
|
|
20
|
+
__exportStar(require("./is-one-of-property.decorator"), exports);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IsOnlyOneOf = IsOnlyOneOf;
|
|
4
|
+
const class_validator_1 = require("class-validator");
|
|
5
|
+
function IsOnlyOneOf(relatedProperty, validationOptions) {
|
|
6
|
+
return function (object, propertyName) {
|
|
7
|
+
(0, class_validator_1.registerDecorator)({
|
|
8
|
+
name: 'isOnlyOneOf',
|
|
9
|
+
target: object.constructor,
|
|
10
|
+
propertyName: propertyName,
|
|
11
|
+
options: validationOptions,
|
|
12
|
+
constraints: [relatedProperty],
|
|
13
|
+
validator: {
|
|
14
|
+
validate(value, args) {
|
|
15
|
+
const relatedValue = args.object[args.constraints[0]];
|
|
16
|
+
return (value && !relatedValue) || (!value && relatedValue);
|
|
17
|
+
},
|
|
18
|
+
defaultMessage(args) {
|
|
19
|
+
return `You can only provide either ${args.property} or ${args.constraints[0]}, but not both.`;
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
}
|
|
@@ -43,31 +43,46 @@ let GlobalExceptionFilter = class GlobalExceptionFilter {
|
|
|
43
43
|
if (type === 'http') {
|
|
44
44
|
const response = context.getResponse();
|
|
45
45
|
try {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
46
|
+
if (exception instanceof common_1.HttpException) {
|
|
47
|
+
const status = exception?.getStatus();
|
|
48
|
+
const result = exception.getResponse();
|
|
49
|
+
const message = typeof result?.message === 'string'
|
|
50
|
+
? result?.message
|
|
51
|
+
: this.isArray(result?.message)
|
|
52
|
+
? result?.message.join(', ')
|
|
53
|
+
: helpers_1.MessageFormatter.replace(enums_1.SharedMessages.OPERATION_FAILED);
|
|
54
|
+
const details = this.isObject(result?.message)
|
|
55
|
+
? {
|
|
56
|
+
cause: result?.message,
|
|
57
|
+
description: result?.error ?? null,
|
|
58
|
+
}
|
|
59
|
+
: {
|
|
60
|
+
cause: exception?.cause ?? null,
|
|
61
|
+
description: result?.error ?? null,
|
|
62
|
+
};
|
|
63
|
+
return response.status(status).json(new dto_1.ErrorResponse({
|
|
64
|
+
name: helpers_1.ConvertStringCaseHelper.toTitleCase(exception?.name),
|
|
65
|
+
message,
|
|
66
|
+
status,
|
|
67
|
+
details,
|
|
68
|
+
}));
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
return response.status(common_1.HttpStatus.INTERNAL_SERVER_ERROR).json(new dto_1.ErrorResponse({
|
|
72
|
+
name: exception?.name
|
|
73
|
+
? exception.name
|
|
74
|
+
: helpers_1.ConvertStringCaseHelper.toTitleCase(common_1.InternalServerErrorException?.name),
|
|
75
|
+
message: helpers_1.MessageFormatter.replace(enums_1.SharedMessages.INTERNAL_SERVER_ERROR),
|
|
76
|
+
status: common_1.HttpStatus.INTERNAL_SERVER_ERROR,
|
|
77
|
+
details: {
|
|
78
|
+
cause: null,
|
|
79
|
+
description: exception?.message ?? null,
|
|
80
|
+
},
|
|
81
|
+
}));
|
|
82
|
+
}
|
|
68
83
|
}
|
|
69
84
|
catch (err) {
|
|
70
|
-
response.status(common_1.HttpStatus.INTERNAL_SERVER_ERROR).json(new dto_1.ErrorResponse({
|
|
85
|
+
return response.status(common_1.HttpStatus.INTERNAL_SERVER_ERROR).json(new dto_1.ErrorResponse({
|
|
71
86
|
name: helpers_1.ConvertStringCaseHelper.toTitleCase(common_1.InternalServerErrorException?.name),
|
|
72
87
|
message: helpers_1.MessageFormatter.replace(enums_1.SharedMessages.INTERNAL_SERVER_ERROR, err),
|
|
73
88
|
status: common_1.HttpStatus.INTERNAL_SERVER_ERROR,
|