@cicctencent/midwayjs-base 1.0.41 → 1.0.43

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.
@@ -3,5 +3,6 @@ export declare class ApiResultFormatterMiddleware implements IMiddleware<IMidway
3
3
  apiOption: any;
4
4
  ignore(ctx: IMidwayContext): boolean;
5
5
  resolve(): (ctx: IMidwayContext, next: any) => Promise<void>;
6
+ isJsonRpc(data: any): boolean;
6
7
  canFormat(data: any): boolean;
7
8
  }
@@ -34,6 +34,9 @@ let ApiResultFormatterMiddleware = class ApiResultFormatterMiddleware {
34
34
  try {
35
35
  await next();
36
36
  const res = koaCtx.body;
37
+ if (this.isJsonRpc(res)) {
38
+ return;
39
+ }
37
40
  if (this.canFormat(res)) {
38
41
  koaCtx.body = Object.assign({
39
42
  ret: 0,
@@ -43,7 +46,10 @@ let ApiResultFormatterMiddleware = class ApiResultFormatterMiddleware {
43
46
  }
44
47
  }
45
48
  catch (err) {
46
- if (err instanceof error_code_1.BizError || typeof err?.ret === 'number') {
49
+ if (this.isJsonRpc(err)) {
50
+ koaCtx.body = err;
51
+ }
52
+ else if (err instanceof error_code_1.BizError || typeof err?.ret === 'number') {
47
53
  koaCtx.body = err instanceof error_code_1.BizError ? err.toJSON() : err;
48
54
  }
49
55
  else {
@@ -64,6 +70,12 @@ let ApiResultFormatterMiddleware = class ApiResultFormatterMiddleware {
64
70
  }
65
71
  };
66
72
  }
73
+ isJsonRpc(data) {
74
+ return (data != null &&
75
+ typeof data === 'object' &&
76
+ 'jsonrpc' in data &&
77
+ ('result' in data || 'error' in data));
78
+ }
67
79
  canFormat(data) {
68
80
  return (data !== '' &&
69
81
  !Buffer.isBuffer(data) &&
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cicctencent/midwayjs-base",
3
- "version": "1.0.41",
3
+ "version": "1.0.43",
4
4
  "description": "基础框架,服务",
5
5
  "main": "dist/index.js",
6
6
  "typings": "index.d.ts",
@@ -38,11 +38,11 @@
38
38
  "mwts": "^1.3.0",
39
39
  "mwtsc": "^1.16.0",
40
40
  "npm-run-all": "^4.1.5",
41
- "ts-jest": "^29.4.10",
41
+ "ts-jest": "^29.4.11",
42
42
  "typescript": "^5.9.3"
43
43
  },
44
44
  "dependencies": {
45
- "@fefeding/common": "^1.0.59",
45
+ "@fefeding/common": "^1.0.60",
46
46
  "@midwayjs/axios": "^3.20.24",
47
47
  "@midwayjs/bootstrap": "^3.20.24",
48
48
  "@midwayjs/cache-manager": "^3.20.24",