@saihu/common 1.1.56 → 1.1.57
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,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';
|
|
3
4
|
export declare class BaseErrorRpcFilter extends BaseRpcExceptionFilter {
|
|
4
|
-
|
|
5
|
-
catch(exception: any, host: ArgumentsHost): import("rxjs").Observable<any>;
|
|
5
|
+
catch(exception: BaseError, 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":"AACA,OAAO,EAAE,aAAa,EAAS,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,sBAAsB,EAAgB,MAAM,uBAAuB,CAAC;AAC7E,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,qBACa,kBAAmB,SAAQ,sBAAsB;IAC5D,KAAK,CAAC,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,aAAa;CAWhD"}
|
|
@@ -5,48 +5,26 @@ 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;
|
|
9
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
9
|
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
|
-
|
|
15
|
-
super(...arguments);
|
|
16
|
-
this.logger = new common_1.Logger(BaseErrorRpcFilter_1.name);
|
|
17
|
-
}
|
|
13
|
+
const base_res_dto_1 = require("../dto/base-res.dto");
|
|
14
|
+
let BaseErrorRpcFilter = class BaseErrorRpcFilter extends microservices_1.BaseRpcExceptionFilter {
|
|
18
15
|
catch(exception, host) {
|
|
19
16
|
var _a;
|
|
20
|
-
//
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
|
17
|
+
// Wrap your BaseError into RpcException payload
|
|
18
|
+
const payload = {
|
|
19
|
+
code: exception.code,
|
|
20
|
+
msg: exception.message,
|
|
21
|
+
data: (_a = exception.data) !== null && _a !== void 0 ? _a : null,
|
|
22
|
+
};
|
|
23
|
+
// Delegate to the base filter with a proper RpcException
|
|
46
24
|
return super.catch(new microservices_1.RpcException(payload), host);
|
|
47
25
|
}
|
|
48
26
|
};
|
|
49
27
|
exports.BaseErrorRpcFilter = BaseErrorRpcFilter;
|
|
50
|
-
exports.BaseErrorRpcFilter = BaseErrorRpcFilter =
|
|
51
|
-
(0, common_1.Catch)()
|
|
28
|
+
exports.BaseErrorRpcFilter = BaseErrorRpcFilter = __decorate([
|
|
29
|
+
(0, common_1.Catch)(base_res_dto_1.BaseError)
|
|
52
30
|
], BaseErrorRpcFilter);
|