@saihu/common 1.1.55 → 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,6 +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
|
-
catch(exception:
|
|
5
|
+
catch(exception: BaseError, 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;
|
|
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"}
|
|
@@ -10,36 +10,21 @@ exports.BaseErrorRpcFilter = void 0;
|
|
|
10
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
|
+
const base_res_dto_1 = require("../dto/base-res.dto");
|
|
13
14
|
let BaseErrorRpcFilter = class BaseErrorRpcFilter extends microservices_1.BaseRpcExceptionFilter {
|
|
14
15
|
catch(exception, host) {
|
|
15
16
|
var _a;
|
|
16
|
-
//
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
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,
|
|
31
|
-
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,
|
|
38
|
-
};
|
|
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
|
|
39
24
|
return super.catch(new microservices_1.RpcException(payload), host);
|
|
40
25
|
}
|
|
41
26
|
};
|
|
42
27
|
exports.BaseErrorRpcFilter = BaseErrorRpcFilter;
|
|
43
28
|
exports.BaseErrorRpcFilter = BaseErrorRpcFilter = __decorate([
|
|
44
|
-
(0, common_1.Catch)(
|
|
29
|
+
(0, common_1.Catch)(base_res_dto_1.BaseError)
|
|
45
30
|
], BaseErrorRpcFilter);
|