@mondart/nestjs-common-module 1.1.63 → 1.1.64

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,2 @@
1
+ import { ValidationOptions } from 'class-validator';
2
+ export declare function IsOnlyOneOf(relatedProperty: string, validationOptions?: ValidationOptions): (object: object, propertyName: string) => void;
@@ -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
- const status = exception?.getStatus();
47
- const result = exception.getResponse();
48
- const message = typeof result?.message === 'string'
49
- ? result?.message
50
- : this.isArray(result?.message)
51
- ? result?.message.join(', ')
52
- : helpers_1.MessageFormatter.replace(enums_1.SharedMessages.OPERATION_FAILED);
53
- const details = this.isObject(result?.message)
54
- ? {
55
- cause: result?.message,
56
- description: result?.error ?? null,
57
- }
58
- : {
59
- cause: exception?.options?.cause ?? null,
60
- description: exception?.options?.description ?? result?.error ?? null,
61
- };
62
- return response.status(status).json(new dto_1.ErrorResponse({
63
- name: helpers_1.ConvertStringCaseHelper.toTitleCase(exception?.name),
64
- message,
65
- status,
66
- details,
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,