@mondart/nestjs-common-module 1.1.20 → 1.1.22

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.
@@ -1,9 +1,9 @@
1
- import { KafkaFailedResponseInterface } from "../../interface/kafka-failed-response.interface";
2
- import { BaseKafkaErrorResponseDto } from "./base-kafka-error-response.dto";
1
+ import { KafkaFailedResponseInterface } from '../../interface/kafka-failed-response.interface';
2
+ import { BaseKafkaErrorResponseDto } from './base-kafka-error-response.dto';
3
3
  export declare class KafkaFailedResponseDto extends BaseKafkaErrorResponseDto {
4
4
  constructor({ data, event_source, topic, model, event_key, partition, status, }: KafkaFailedResponseInterface);
5
- notFound(message?: string): void;
6
- badRequest(message?: string): void;
7
- internalServer(message?: string): void;
5
+ notFound(message?: string): this;
6
+ badRequest(message?: string): this;
7
+ internalServer(message?: string): this;
8
8
  stringify(): string;
9
9
  }
@@ -20,14 +20,17 @@ class KafkaFailedResponseDto extends base_kafka_error_response_dto_1.BaseKafkaEr
20
20
  notFound(message) {
21
21
  this.status = common_1.HttpStatus.NOT_FOUND;
22
22
  this.data = new error_response_dto_1.ErrorResponse(helpers_1.MessageFormatter.replace(enums_1.SharedMessages.RESOURCE_NOT_FOUND, message), this.status);
23
+ return this;
23
24
  }
24
25
  badRequest(message) {
25
26
  this.status = common_1.HttpStatus.BAD_REQUEST;
26
27
  this.data = new error_response_dto_1.ErrorResponse(helpers_1.MessageFormatter.replace(enums_1.SharedMessages.PARAMETER_VALIDATION_FAILED, message), this.status);
28
+ return this;
27
29
  }
28
30
  internalServer(message) {
29
31
  this.status = common_1.HttpStatus.INTERNAL_SERVER_ERROR;
30
32
  this.data = new error_response_dto_1.ErrorResponse(helpers_1.MessageFormatter.replace(enums_1.SharedMessages.INTERNAL_SERVER_ERROR, message), this.status);
33
+ return this;
31
34
  }
32
35
  stringify() {
33
36
  return JSON.stringify(this);
@@ -1,8 +1,8 @@
1
1
  import { ArgumentsHost, ExceptionFilter, HttpException } from '@nestjs/common';
2
2
  import { Response } from 'express';
3
3
  import { ConfigService } from '@nestjs/config';
4
- export declare class HttpExceptionFilter implements ExceptionFilter {
4
+ export declare class GlobalExceptionFilter implements ExceptionFilter {
5
5
  private readonly configService;
6
6
  constructor(configService: ConfigService);
7
- catch(exception: HttpException, host: ArgumentsHost): Response<any, Record<string, any>>;
7
+ catch(exception: HttpException, host: ArgumentsHost): Response<any, Record<string, any>> | import("rxjs").Observable<never>;
8
8
  }
@@ -9,13 +9,14 @@ var __metadata = (this && this.__metadata) || function (k, v) {
9
9
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.HttpExceptionFilter = void 0;
12
+ exports.GlobalExceptionFilter = void 0;
13
13
  const common_1 = require("@nestjs/common");
14
14
  const dto_1 = require("../dto");
15
15
  const config_1 = require("@nestjs/config");
16
- const shared_messages_enum_1 = require("../enums/shared-messages.enum");
16
+ const enums_1 = require("../enums");
17
17
  const microservices_1 = require("@nestjs/microservices");
18
- let HttpExceptionFilter = class HttpExceptionFilter {
18
+ const rxjs_1 = require("rxjs");
19
+ let GlobalExceptionFilter = class GlobalExceptionFilter {
19
20
  constructor(configService) {
20
21
  this.configService = configService;
21
22
  }
@@ -25,11 +26,12 @@ let HttpExceptionFilter = class HttpExceptionFilter {
25
26
  const status = exception.getStatus();
26
27
  const result = exception.getResponse();
27
28
  const logger = new common_1.Logger('OrderKafkaController', { timestamp: true });
28
- if (response instanceof microservices_1.KafkaContext) {
29
- logger.error(result);
30
- }
31
29
  try {
32
- if (status === common_1.HttpStatus.UNPROCESSABLE_ENTITY) {
30
+ if (exception instanceof microservices_1.RpcException) {
31
+ logger.error(result);
32
+ return (0, rxjs_1.throwError)(() => exception);
33
+ }
34
+ else if (status === common_1.HttpStatus.UNPROCESSABLE_ENTITY) {
33
35
  return response.status(status).json(result);
34
36
  }
35
37
  else if (status === common_1.HttpStatus.BAD_REQUEST) {
@@ -53,12 +55,12 @@ let HttpExceptionFilter = class HttpExceptionFilter {
53
55
  catch (err) {
54
56
  response
55
57
  .status(common_1.HttpStatus.INTERNAL_SERVER_ERROR)
56
- .json(new dto_1.ErrorResponse(shared_messages_enum_1.SharedMessages.INTERNAL_SERVER_ERROR, common_1.HttpStatus.INTERNAL_SERVER_ERROR));
58
+ .json(new dto_1.ErrorResponse(enums_1.SharedMessages.INTERNAL_SERVER_ERROR, common_1.HttpStatus.INTERNAL_SERVER_ERROR));
57
59
  }
58
60
  }
59
61
  };
60
- exports.HttpExceptionFilter = HttpExceptionFilter;
61
- exports.HttpExceptionFilter = HttpExceptionFilter = __decorate([
62
- (0, common_1.Catch)(common_1.HttpException),
62
+ exports.GlobalExceptionFilter = GlobalExceptionFilter;
63
+ exports.GlobalExceptionFilter = GlobalExceptionFilter = __decorate([
64
+ (0, common_1.Catch)(),
63
65
  __metadata("design:paramtypes", [config_1.ConfigService])
64
- ], HttpExceptionFilter);
66
+ ], GlobalExceptionFilter);
@@ -1 +1 @@
1
- export * from './http-exception.filter';
1
+ export * from './global-exception.filter';
@@ -14,4 +14,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./http-exception.filter"), exports);
17
+ __exportStar(require("./global-exception.filter"), exports);
@@ -1,4 +1,5 @@
1
1
  export declare class ConvertStringCaseHelper {
2
2
  static pascalToKebab(str: string): string;
3
3
  static camelToKebab(str: string): string;
4
+ static snakeToKebab(str: string): string;
4
5
  }
@@ -11,5 +11,8 @@ class ConvertStringCaseHelper {
11
11
  static camelToKebab(str) {
12
12
  return str.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();
13
13
  }
14
+ static snakeToKebab(str) {
15
+ return str.replaceAll('_', '-');
16
+ }
14
17
  }
15
18
  exports.ConvertStringCaseHelper = ConvertStringCaseHelper;
@@ -78,7 +78,7 @@ let CoreCrudService = class CoreCrudService {
78
78
  });
79
79
  }
80
80
  if (options?.existsCheck && !result) {
81
- throw new common_1.NotFoundException(enums_1.SharedMessages.RESOURCE_NOT_FOUND);
81
+ throw new common_1.NotFoundException(helpers_1.MessageFormatter.replace(enums_1.SharedMessages.RESOURCE_NOT_FOUND, `${helpers_1.ConvertStringCaseHelper.snakeToKebab(this.repository.metadata?.tableName)}-id: ${id}`));
82
82
  }
83
83
  return result;
84
84
  }