@nmxjs/api 1.2.8 → 1.2.10

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,5 +1,9 @@
1
1
  /// <reference types="types" />
2
2
  import { NestInterceptor, CallHandler, ExecutionContext } from '@nestjs/common';
3
+ import type { INotifier } from '@nmxjs/notifications';
3
4
  export declare class RpcExceptionInterceptor implements NestInterceptor {
5
+ protected readonly debug: boolean;
6
+ protected readonly notifier?: INotifier;
7
+ constructor(debug?: boolean, notifier?: INotifier);
4
8
  intercept(context: ExecutionContext, next: CallHandler): any;
5
9
  }
@@ -5,6 +5,9 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
5
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
6
  return c > 3 && r && Object.defineProperty(target, key, r), r;
7
7
  };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
8
11
  Object.defineProperty(exports, "__esModule", { value: true });
9
12
  exports.RpcExceptionInterceptor = void 0;
10
13
  const rxjs_1 = require("rxjs");
@@ -13,32 +16,46 @@ const utils_1 = require("@nmxjs/utils");
13
16
  const common_1 = require("@nestjs/common");
14
17
  const constants_1 = require("../constants");
15
18
  let RpcExceptionInterceptor = class RpcExceptionInterceptor {
19
+ constructor(debug = false, notifier) {
20
+ this.debug = debug;
21
+ this.notifier = notifier;
22
+ }
16
23
  intercept(context, next) {
17
24
  var _a, _b, _c;
18
25
  const requestId = (0, utils_1.uuid)();
19
26
  const path = (_c = (_b = (_a = context.getArgByIndex(2)) === null || _a === void 0 ? void 0 : _a.call) === null || _b === void 0 ? void 0 : _b.handler) === null || _c === void 0 ? void 0 : _c.path;
20
- common_1.Logger.debug(`Rpc Request: ${(0, utils_1.readableJson)(Object.assign({ requestId, data: context.getArgByIndex(0) }, (path ? { path } : { event: context.getArgByIndex(1).args[0] })))}`);
27
+ if (this.debug) {
28
+ common_1.Logger.debug(`Rpc Request: ${(0, utils_1.readableJson)(Object.assign({ requestId, data: context.getArgByIndex(0) }, (path ? { path } : { event: context.getArgByIndex(1).args[0] })))}`);
29
+ }
21
30
  return next.handle().pipe((0, rxjs_1.tap)(data => {
22
- common_1.Logger.debug(`Rpc Response: ${(0, utils_1.readableJson)({
23
- requestId,
24
- data,
25
- })}`);
31
+ if (this.debug) {
32
+ common_1.Logger.debug(`Rpc Response: ${(0, utils_1.readableJson)({
33
+ requestId,
34
+ data,
35
+ })}`);
36
+ }
26
37
  }), (0, rxjs_1.catchError)(e => {
27
38
  const splitResult = e.message.split(constants_1.endErrorText);
28
39
  const errorMessage = splitResult.length === 1 ? e.stack : splitResult[0];
29
- common_1.Logger.debug(`Rpc Response: ${(0, utils_1.readableJson)({
30
- requestId,
31
- error: {
32
- message: errorMessage,
33
- },
34
- })}`);
40
+ if (this.debug) {
41
+ common_1.Logger.debug(`Rpc Response: ${(0, utils_1.readableJson)({
42
+ requestId,
43
+ error: {
44
+ message: errorMessage,
45
+ },
46
+ })}`);
47
+ }
35
48
  common_1.Logger.error(errorMessage);
49
+ if (this.notifier && !e.silent) {
50
+ this.notifier.sendError({ message: errorMessage });
51
+ }
36
52
  throw new microservices_1.RpcException(`${errorMessage}${constants_1.endErrorText}`);
37
53
  }));
38
54
  }
39
55
  };
40
56
  exports.RpcExceptionInterceptor = RpcExceptionInterceptor;
41
57
  exports.RpcExceptionInterceptor = RpcExceptionInterceptor = __decorate([
42
- (0, common_1.Injectable)()
58
+ (0, common_1.Injectable)(),
59
+ __metadata("design:paramtypes", [Boolean, Object])
43
60
  ], RpcExceptionInterceptor);
44
61
  //# sourceMappingURL=RpcExceptionInterceptor.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"RpcExceptionInterceptor.js","sourceRoot":"","sources":["../../../src/ApiRouterCore/utils/RpcExceptionInterceptor.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@nmxjs/api",
3
- "version": "1.2.8",
3
+ "version": "1.2.10",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -40,6 +40,7 @@
40
40
  "peerDependencies": {
41
41
  "@nestjs/graphql": "^13.0.2",
42
42
  "@nmxjs/config": "^1.0.15",
43
- "@nestjs/common": "^11.0.7"
43
+ "@nestjs/common": "^11.0.7",
44
+ "@nmxjs/notifications": "^1.0.5"
44
45
  }
45
46
  }
package/types.d.ts CHANGED
@@ -69,3 +69,8 @@ declare module '@nmxjs/config' {
69
69
  const configKey: string;
70
70
  const getConfig: () => IConfig;
71
71
  }
72
+ declare module '@nmxjs/notifications' {
73
+ interface INotifier {
74
+ sendError(error: { message: string }): void;
75
+ }
76
+ }