@saihu/common 1.1.54 → 1.1.56
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.
- package/dist/filters/base-error-rpc.filter.d.ts +2 -2
- package/dist/filters/base-error-rpc.filter.d.ts.map +1 -1
- package/dist/filters/base-error-rpc.filter.js +34 -12
- package/dist/messaging/topology.js +1 -1
- package/dist/services/rabbitmq.service.d.ts.map +1 -1
- package/dist/services/rabbitmq.service.js +2 -1
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ArgumentsHost } from '@nestjs/common';
|
|
2
2
|
import { BaseRpcExceptionFilter } from '@nestjs/microservices';
|
|
3
|
-
import { BaseError } from '../dto/base-res.dto';
|
|
4
3
|
export declare class BaseErrorRpcFilter extends BaseRpcExceptionFilter {
|
|
5
|
-
|
|
4
|
+
private readonly logger;
|
|
5
|
+
catch(exception: any, host: ArgumentsHost): import("rxjs").Observable<any>;
|
|
6
6
|
}
|
|
7
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":"
|
|
1
|
+
{"version":3,"file":"base-error-rpc.filter.d.ts","sourceRoot":"","sources":["../../src/filters/base-error-rpc.filter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAiB,MAAM,gBAAgB,CAAC;AAC9D,OAAO,EAAE,sBAAsB,EAAgB,MAAM,uBAAuB,CAAC;AAE7E,qBACa,kBAAmB,SAAQ,sBAAsB;IAC5D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAuC;IAE9D,KAAK,CAAC,SAAS,EAAE,GAAG,EAAE,IAAI,EAAE,aAAa;CAmC1C"}
|
|
@@ -5,26 +5,48 @@ 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
|
-
// @saihu/common/src/filters/base-error-rpc.filter.ts
|
|
11
11
|
const common_1 = require("@nestjs/common");
|
|
12
12
|
const microservices_1 = require("@nestjs/microservices");
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
let BaseErrorRpcFilter = BaseErrorRpcFilter_1 = class BaseErrorRpcFilter extends microservices_1.BaseRpcExceptionFilter {
|
|
14
|
+
constructor() {
|
|
15
|
+
super(...arguments);
|
|
16
|
+
this.logger = new common_1.Logger(BaseErrorRpcFilter_1.name);
|
|
17
|
+
}
|
|
15
18
|
catch(exception, host) {
|
|
16
19
|
var _a;
|
|
17
|
-
//
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
// Only handle RPC context
|
|
21
|
+
if (host.getType() !== 'rpc') {
|
|
22
|
+
return super.catch(exception, host);
|
|
23
|
+
}
|
|
24
|
+
// If it's already an RpcException, pass through
|
|
25
|
+
if (exception instanceof microservices_1.RpcException) {
|
|
26
|
+
return super.catch(exception, host);
|
|
27
|
+
}
|
|
28
|
+
// Log the original error for debugging
|
|
29
|
+
this.logger.error('RPC Error caught:', exception);
|
|
30
|
+
// Transform to standardized format
|
|
31
|
+
const isBaseErrorLike = (exception === null || exception === void 0 ? void 0 : exception.name) === 'BaseError' ||
|
|
32
|
+
(typeof (exception === null || exception === void 0 ? void 0 : exception.code) === 'number' &&
|
|
33
|
+
typeof (exception === null || exception === void 0 ? void 0 : exception.message) === 'string');
|
|
34
|
+
const payload = isBaseErrorLike
|
|
35
|
+
? {
|
|
36
|
+
code: Number(exception.code) || 500,
|
|
37
|
+
msg: exception.message || 'Internal server error',
|
|
38
|
+
data: (_a = exception.data) !== null && _a !== void 0 ? _a : null,
|
|
39
|
+
}
|
|
40
|
+
: {
|
|
41
|
+
code: 500,
|
|
42
|
+
msg: (exception === null || exception === void 0 ? void 0 : exception.message) || 'Internal server error',
|
|
43
|
+
data: null,
|
|
44
|
+
};
|
|
45
|
+
// Always wrap in RpcException before passing to super
|
|
24
46
|
return super.catch(new microservices_1.RpcException(payload), host);
|
|
25
47
|
}
|
|
26
48
|
};
|
|
27
49
|
exports.BaseErrorRpcFilter = BaseErrorRpcFilter;
|
|
28
|
-
exports.BaseErrorRpcFilter = BaseErrorRpcFilter = __decorate([
|
|
29
|
-
(0, common_1.Catch)(
|
|
50
|
+
exports.BaseErrorRpcFilter = BaseErrorRpcFilter = BaseErrorRpcFilter_1 = __decorate([
|
|
51
|
+
(0, common_1.Catch)()
|
|
30
52
|
], BaseErrorRpcFilter);
|
|
@@ -93,7 +93,7 @@ exports.ExchangeTypes = {
|
|
|
93
93
|
[Exchanges.IM_DATA]: 'topic',
|
|
94
94
|
[Exchanges.IM_INVENTORY]: 'topic',
|
|
95
95
|
[Exchanges.MASTER_DATA]: 'topic',
|
|
96
|
-
[Exchanges.OPER_LOG_EXCHANGE]: '
|
|
96
|
+
[Exchanges.OPER_LOG_EXCHANGE]: 'topic',
|
|
97
97
|
[Exchanges.IM_SALES_ORDER]: 'topic',
|
|
98
98
|
[Exchanges.SCM_DATA]: 'topic',
|
|
99
99
|
[Exchanges.IM_PROCUREMENT_ORDER_DLX]: 'topic',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rabbitmq.service.d.ts","sourceRoot":"","sources":["../../src/services/rabbitmq.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,YAAY,EACZ,eAAe,EAGhB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;
|
|
1
|
+
{"version":3,"file":"rabbitmq.service.d.ts","sourceRoot":"","sources":["../../src/services/rabbitmq.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,YAAY,EACZ,eAAe,EAGhB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAEtE,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAGlE,qBACa,mBACX,YAAW,eAAe,EAAE,YAAY,EAAE,eAAe;IAUvD,OAAO,CAAC,QAAQ,CAAC,OAAO;IAR1B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAwC;IAC/D,OAAO,CAAC,UAAU,CAAgC;IAClD,OAAO,CAAC,OAAO,CAA2B;IAC1C,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,SAAS,CAAU;gBAIR,OAAO,EAAE,mBAAmB;IAKzC,YAAY;IAMZ,eAAe;IAIf,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IA6BxB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAY3B,cAAc,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC;CAkBrD"}
|
|
@@ -50,6 +50,7 @@ exports.RabbitmqServiceImpl = void 0;
|
|
|
50
50
|
const common_1 = require("@nestjs/common");
|
|
51
51
|
const amqp = __importStar(require("amqplib"));
|
|
52
52
|
const common_consts_1 = require("../consts/common.consts");
|
|
53
|
+
const messaging_1 = require("../messaging");
|
|
53
54
|
let RabbitmqServiceImpl = RabbitmqServiceImpl_1 = class RabbitmqServiceImpl {
|
|
54
55
|
constructor(options) {
|
|
55
56
|
this.options = options;
|
|
@@ -110,7 +111,7 @@ let RabbitmqServiceImpl = RabbitmqServiceImpl_1 = class RabbitmqServiceImpl {
|
|
|
110
111
|
}
|
|
111
112
|
try {
|
|
112
113
|
const messageBuffer = Buffer.from(JSON.stringify(message));
|
|
113
|
-
return this.channel.publish(
|
|
114
|
+
return this.channel.publish(messaging_1.Exchanges.OPER_LOG_EXCHANGE, messaging_1.RoutingKeys[messaging_1.Exchanges.OPER_LOG_EXCHANGE].OPER_LOG_CREATED, messageBuffer);
|
|
114
115
|
}
|
|
115
116
|
catch (error) {
|
|
116
117
|
this.logger.error('Failed to publish message to RabbitMQ:', error);
|