rpc-express-toolkit 4.3.2 → 4.3.3
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/package.json +1 -1
- package/src/batch.js +13 -2
- package/src/index.js +6 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rpc-express-toolkit",
|
|
3
|
-
"version": "4.3.
|
|
3
|
+
"version": "4.3.3",
|
|
4
4
|
"description": "Enterprise-ready JSON-RPC 2.0 toolkit for Express.js with simplified APIs, structured logging, middleware system, schema validation, comprehensive BigInt/Date support. JSON middleware validation and explicit configuration.",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"types": "src/index.d.ts",
|
package/src/batch.js
CHANGED
|
@@ -9,6 +9,14 @@ class BatchHandler {
|
|
|
9
9
|
this.endpoint = endpoint;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
+
serializeErrorData(error, batchIndex) {
|
|
13
|
+
const errorWithBatchIndex = addBatchIndex(error, batchIndex);
|
|
14
|
+
if (!hasOwn(errorWithBatchIndex, 'data')) {
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
return this.endpoint.serializeBigIntsAndDates(errorWithBatchIndex.data);
|
|
18
|
+
}
|
|
19
|
+
|
|
12
20
|
/**
|
|
13
21
|
* Check if request is a batch request
|
|
14
22
|
* @param {any} body
|
|
@@ -70,13 +78,14 @@ class BatchHandler {
|
|
|
70
78
|
try {
|
|
71
79
|
return await this.processSingleRequest(request, req, context, index);
|
|
72
80
|
} catch (error) {
|
|
81
|
+
const errorData = this.serializeErrorData(error, index);
|
|
73
82
|
return {
|
|
74
83
|
jsonrpc: '2.0',
|
|
75
84
|
id: request && hasOwn(request, 'id') ? request.id : null,
|
|
76
85
|
error: {
|
|
77
86
|
code: error.code || -32603,
|
|
78
87
|
message: error.message || 'Internal error',
|
|
79
|
-
data:
|
|
88
|
+
...(errorData !== undefined && { data: errorData }),
|
|
80
89
|
},
|
|
81
90
|
};
|
|
82
91
|
}
|
|
@@ -269,13 +278,15 @@ class BatchHandler {
|
|
|
269
278
|
return null;
|
|
270
279
|
}
|
|
271
280
|
|
|
281
|
+
const errorData = this.serializeErrorData(error, batchIndex);
|
|
282
|
+
|
|
272
283
|
return {
|
|
273
284
|
jsonrpc: '2.0',
|
|
274
285
|
id,
|
|
275
286
|
error: {
|
|
276
287
|
code: error.code || -32603,
|
|
277
288
|
message: error.message || 'Internal error',
|
|
278
|
-
data:
|
|
289
|
+
...(errorData !== undefined && { data: errorData }),
|
|
279
290
|
},
|
|
280
291
|
};
|
|
281
292
|
}
|
package/src/index.js
CHANGED
|
@@ -675,12 +675,17 @@ class RpcEndpoint {
|
|
|
675
675
|
return null;
|
|
676
676
|
}
|
|
677
677
|
|
|
678
|
+
const errorData =
|
|
679
|
+
hasOwn(err, 'data') && err.data !== undefined
|
|
680
|
+
? this.serializeBigIntsAndDates(err.data)
|
|
681
|
+
: undefined;
|
|
682
|
+
|
|
678
683
|
this.reply(res, {
|
|
679
684
|
id,
|
|
680
685
|
error: {
|
|
681
686
|
code: err.code || -32603,
|
|
682
687
|
message: err.message || `Internal error`,
|
|
683
|
-
...(
|
|
688
|
+
...(errorData !== undefined && { data: errorData }),
|
|
684
689
|
error: serializeError(err, true),
|
|
685
690
|
},
|
|
686
691
|
});
|