@saihu/common 1.1.62 → 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.
@@ -1,6 +1,7 @@
1
1
  import { ArgumentsHost } from '@nestjs/common';
2
2
  import { BaseRpcExceptionFilter } from '@nestjs/microservices';
3
3
  export declare class BaseErrorRpcFilter extends BaseRpcExceptionFilter {
4
+ private readonly logger;
4
5
  catch(exception: any, host: ArgumentsHost): import("rxjs").Observable<any>;
5
6
  }
6
7
  //# 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,EAAS,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,sBAAsB,EAAgB,MAAM,uBAAuB,CAAC;AAE7E,qBACa,kBAAmB,SAAQ,sBAAsB;IAC5D,KAAK,CAAC,SAAS,EAAE,GAAG,EAAE,IAAI,EAAE,aAAa;CA+B1C"}
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;CAuD1C"}
@@ -5,41 +5,63 @@ 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 BaseErrorRpcFilter_1;
8
9
  Object.defineProperty(exports, "__esModule", { value: true });
9
10
  exports.BaseErrorRpcFilter = void 0;
10
11
  // @saihu/common/src/filters/base-error-rpc.filter.ts
11
12
  const common_1 = require("@nestjs/common");
12
13
  const microservices_1 = require("@nestjs/microservices");
13
- let BaseErrorRpcFilter = class BaseErrorRpcFilter extends microservices_1.BaseRpcExceptionFilter {
14
+ const base_res_dto_1 = require("../dto/base-res.dto");
15
+ let BaseErrorRpcFilter = BaseErrorRpcFilter_1 = class BaseErrorRpcFilter extends microservices_1.BaseRpcExceptionFilter {
16
+ constructor() {
17
+ super(...arguments);
18
+ this.logger = new common_1.Logger(BaseErrorRpcFilter_1.name);
19
+ }
14
20
  catch(exception, host) {
15
- var _a;
16
- // Only transform for RPC
17
- if (host.getType() !== 'rpc') {
18
- return super.catch(exception, host);
19
- }
20
- // If it's already RpcException, pass through
21
+ var _a, _b;
22
+ console.log('=== BaseErrorRpcFilter TRIGGERED ===');
23
+ console.log('Exception type:', (_a = exception === null || exception === void 0 ? void 0 : exception.constructor) === null || _a === void 0 ? void 0 : _a.name);
24
+ console.log('Exception name:', exception === null || exception === void 0 ? void 0 : exception.name);
25
+ console.log('Exception instanceof BaseError:', exception instanceof base_res_dto_1.BaseError);
26
+ console.log('Exception instanceof RpcException:', exception instanceof microservices_1.RpcException);
27
+ console.log('Exception keys:', Object.keys(exception || {}));
28
+ console.log('Exception:', exception);
29
+ console.log('Host type:', host.getType());
30
+ console.log('=====================================');
31
+ // Skip if already an RpcException
21
32
  if (exception instanceof microservices_1.RpcException) {
33
+ console.log('Already RpcException, passing through');
22
34
  return super.catch(exception, host);
23
35
  }
24
- // Duck-type check for your BaseError shape
25
- const isBaseErrorLike = ((exception === null || exception === void 0 ? void 0 : exception.name) === 'BaseError' ||
26
- typeof (exception === null || exception === void 0 ? void 0 : exception.code) === 'number') &&
27
- typeof (exception === null || exception === void 0 ? void 0 : exception.message) === 'string';
28
- const payload = isBaseErrorLike
29
- ? {
30
- code: Number(exception.code) || 500,
36
+ // Check if it's a BaseError using duck-typing
37
+ const isBaseErrorLike = exception &&
38
+ typeof exception === 'object' &&
39
+ exception.name === 'BaseError' &&
40
+ typeof exception.code === 'number' &&
41
+ typeof exception.message === 'string';
42
+ console.log('isBaseErrorLike:', isBaseErrorLike);
43
+ if (isBaseErrorLike || exception instanceof base_res_dto_1.BaseError) {
44
+ const payload = {
45
+ code: exception.code,
31
46
  msg: exception.message,
32
- data: (_a = exception.data) !== null && _a !== void 0 ? _a : null,
33
- }
34
- : {
35
- code: 500,
36
- msg: 'Internal server error',
37
- data: null,
47
+ data: (_b = exception.data) !== null && _b !== void 0 ? _b : null,
38
48
  };
49
+ console.log('Transforming to RpcException with payload:', payload);
50
+ this.logger.log(`BaseError caught: [${payload.code}] ${payload.msg}`);
51
+ return super.catch(new microservices_1.RpcException(payload), host);
52
+ }
53
+ // Handle all other errors
54
+ console.log('Unhandled error, wrapping as 500');
55
+ this.logger.error('Unhandled RPC error:', exception);
56
+ const payload = {
57
+ code: 500,
58
+ msg: (exception === null || exception === void 0 ? void 0 : exception.message) || 'Internal server error',
59
+ data: null,
60
+ };
39
61
  return super.catch(new microservices_1.RpcException(payload), host);
40
62
  }
41
63
  };
42
64
  exports.BaseErrorRpcFilter = BaseErrorRpcFilter;
43
- exports.BaseErrorRpcFilter = BaseErrorRpcFilter = __decorate([
44
- (0, common_1.Catch)() // <-- catch everything (not just BaseError)
65
+ exports.BaseErrorRpcFilter = BaseErrorRpcFilter = BaseErrorRpcFilter_1 = __decorate([
66
+ (0, common_1.Catch)() // Catch everything
45
67
  ], BaseErrorRpcFilter);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saihu/common",
3
- "version": "1.1.62",
3
+ "version": "1.1.64",
4
4
  "description": "Common utilities for NestJS applications",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",