rpc-websockets
rpc-websockets copied to clipboard
Ignore null in result/error
Hi! 👋
Firstly, thanks for your work on this project! 🙂
Today I used patch-package to patch [email protected]
for the project I'm working on.
whitebit.com sends "error: null" and I constantly get Server response malformed. Response must include either \"result\"" + " or \"error\", but not both.
Here is the diff that solved my problem:
diff --git a/node_modules/rpc-websockets/dist/lib/client.js b/node_modules/rpc-websockets/dist/lib/client.js
index f07ce1d..2207e56 100644
--- a/node_modules/rpc-websockets/dist/lib/client.js
+++ b/node_modules/rpc-websockets/dist/lib/client.js
@@ -451,6 +451,12 @@ var CommonClient = /*#__PURE__*/function (_EventEmitter) {
} // reject early since server's response is invalid
+ if (message.error === null) {
+ delete message.error
+ }if (message.result === null) {
+ delete message.result
+ }
+
if ("error" in message === "result" in message) _this4.queue[message.id].promise[1](new Error("Server response malformed. Response must include either \"result\"" + " or \"error\", but not both."));
if (_this4.queue[message.id].timeout) clearTimeout(_this4.queue[message.id].timeout);
if (message.error) _this4.queue[message.id].promise[1](message.error);else _this4.queue[message.id].promise[0](message.result);
This issue body was partially generated by patch-package.
What's your response json? Does it abide to the spec?
@mkozjak whitebit.com API sends "error: null, response: ..." or "error: ..., response: null".