@saihu/common 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.
@@ -2,6 +2,7 @@ import { ArgumentsHost } from '@nestjs/common';
2
2
  import { BaseRpcExceptionFilter } from '@nestjs/microservices';
3
3
  export declare class BaseErrorRpcFilter extends BaseRpcExceptionFilter {
4
4
  private readonly logger;
5
+ constructor();
5
6
  catch(exception: any, host: ArgumentsHost): import("rxjs").Observable<any>;
6
7
  }
7
8
  //# sourceMappingURL=base-error-rpc.filter.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"base-error-rpc.filter.d.ts","sourceRoot":"","sources":["../../src/filters/base-error-rpc.filter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAiB,MAAM,gBAAgB,CAAC;AAC9D,OAAO,EAAE,sBAAsB,EAAgB,MAAM,uBAAuB,CAAC;AAG7E,qBACa,kBAAmB,SAAQ,sBAAsB;IAC5D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAuC;IAE9D,KAAK,CAAC,SAAS,EAAE,GAAG,EAAE,IAAI,EAAE,aAAa;CAwC1C"}
1
+ {"version":3,"file":"base-error-rpc.filter.d.ts","sourceRoot":"","sources":["../../src/filters/base-error-rpc.filter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAiB,MAAM,gBAAgB,CAAC;AAC9D,OAAO,EAAE,sBAAsB,EAAgB,MAAM,uBAAuB,CAAC;AAG7E,qBACa,kBAAmB,SAAQ,sBAAsB;IAC5D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAuC;;IAQ9D,KAAK,CAAC,SAAS,EAAE,GAAG,EAAE,IAAI,EAAE,aAAa;CAuD1C"}
@@ -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
  var BaseErrorRpcFilter_1;
9
12
  Object.defineProperty(exports, "__esModule", { value: true });
10
13
  exports.BaseErrorRpcFilter = void 0;
@@ -14,38 +17,47 @@ const microservices_1 = require("@nestjs/microservices");
14
17
  const base_res_dto_1 = require("../dto/base-res.dto");
15
18
  let BaseErrorRpcFilter = BaseErrorRpcFilter_1 = class BaseErrorRpcFilter extends microservices_1.BaseRpcExceptionFilter {
16
19
  constructor() {
17
- super(...arguments);
20
+ super();
18
21
  this.logger = new common_1.Logger(BaseErrorRpcFilter_1.name);
22
+ console.log('!!! BaseErrorRpcFilter CONSTRUCTOR CALLED !!!');
23
+ this.logger.log('BaseErrorRpcFilter initialized');
19
24
  }
20
25
  catch(exception, host) {
21
- var _a;
26
+ var _a, _b;
27
+ console.log('=== BaseErrorRpcFilter TRIGGERED ===');
28
+ console.log('Exception type:', (_a = exception === null || exception === void 0 ? void 0 : exception.constructor) === null || _a === void 0 ? void 0 : _a.name);
29
+ console.log('Exception name:', exception === null || exception === void 0 ? void 0 : exception.name);
30
+ console.log('Exception instanceof BaseError:', exception instanceof base_res_dto_1.BaseError);
31
+ console.log('Exception instanceof RpcException:', exception instanceof microservices_1.RpcException);
32
+ console.log('Exception keys:', Object.keys(exception || {}));
33
+ console.log('Exception:', exception);
34
+ console.log('Host type:', host.getType());
35
+ console.log('=====================================');
22
36
  // Skip if already an RpcException
23
37
  if (exception instanceof microservices_1.RpcException) {
38
+ console.log('Already RpcException, passing through');
24
39
  return super.catch(exception, host);
25
40
  }
26
41
  // Check if it's a BaseError using duck-typing
27
- // This is more reliable than instanceof for serialized errors
28
42
  const isBaseErrorLike = exception &&
29
43
  typeof exception === 'object' &&
30
44
  exception.name === 'BaseError' &&
31
45
  typeof exception.code === 'number' &&
32
46
  typeof exception.message === 'string';
47
+ console.log('isBaseErrorLike:', isBaseErrorLike);
33
48
  if (isBaseErrorLike || exception instanceof base_res_dto_1.BaseError) {
34
49
  const payload = {
35
50
  code: exception.code,
36
51
  msg: exception.message,
37
- data: (_a = exception.data) !== null && _a !== void 0 ? _a : null,
52
+ data: (_b = exception.data) !== null && _b !== void 0 ? _b : null,
38
53
  };
54
+ console.log('Transforming to RpcException with payload:', payload);
39
55
  this.logger.log(`BaseError caught: [${payload.code}] ${payload.msg}`);
40
56
  return super.catch(new microservices_1.RpcException(payload), host);
41
57
  }
42
58
  // Handle all other errors
43
- this.logger.error('Unhandled RPC error:', {
44
- name: exception === null || exception === void 0 ? void 0 : exception.name,
45
- message: exception === null || exception === void 0 ? void 0 : exception.message,
46
- code: exception === null || exception === void 0 ? void 0 : exception.code,
47
- stack: exception === null || exception === void 0 ? void 0 : exception.stack,
48
- });
59
+ console.log('Unhandled error, wrapping as 500');
60
+ this.logger.error('Unhandled RPC error:', exception);
49
61
  const payload = {
50
62
  code: 500,
51
63
  msg: (exception === null || exception === void 0 ? void 0 : exception.message) || 'Internal server error',
@@ -57,4 +69,6 @@ let BaseErrorRpcFilter = BaseErrorRpcFilter_1 = class BaseErrorRpcFilter extends
57
69
  exports.BaseErrorRpcFilter = BaseErrorRpcFilter;
58
70
  exports.BaseErrorRpcFilter = BaseErrorRpcFilter = BaseErrorRpcFilter_1 = __decorate([
59
71
  (0, common_1.Catch)() // Catch everything
72
+ ,
73
+ __metadata("design:paramtypes", [])
60
74
  ], BaseErrorRpcFilter);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saihu/common",
3
- "version": "1.1.63",
3
+ "version": "1.1.65",
4
4
  "description": "Common utilities for NestJS applications",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",