From f1c9e8a788a47f26d217c43be7ab8a380da47184 Mon Sep 17 00:00:00 2001 From: gstaff Date: Sun, 4 Dec 2016 09:35:54 -0600 Subject: [PATCH 1/3] Add newline to communicate over TCP socket. --- src/connection.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/connection.js b/src/connection.js index 73110ec..1cf49fb 100644 --- a/src/connection.js +++ b/src/connection.js @@ -40,7 +40,7 @@ module.exports = function (classes){ params : params, id : id }); - this.write(data); + this.write(data + '\n'); }, /** @@ -128,4 +128,4 @@ module.exports = function (classes){ }); return Connection; -}; \ No newline at end of file +}; From 07bfd84a528a6d161b9507a6e3e2f347171e1f3e Mon Sep 17 00:00:00 2001 From: Evgeny Copisoff Date: Wed, 12 Jul 2017 10:08:30 +0300 Subject: [PATCH 2/3] Success answer without error field. Error answer without result field. --- src/connection.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/connection.js b/src/connection.js index 1cf49fb..201dc2f 100644 --- a/src/connection.js +++ b/src/connection.js @@ -115,15 +115,16 @@ module.exports = function (classes){ } }, - sendReply: function (err, result, id){ - var data = JSON.stringify({ - jsonrpc: '2.0', - result : result, - error : err, - id : id - }); - - this.write(data); + sendReply: function (error, result, id){ + const jsonrpc = '2.0' + let data = { result, error, id, jsonrpc }; + for (let key of Object.keys(data)){ + if (_.isNull(data[key])){ + delete data[key]; + } + } + let send = JSON.stringify(data); + this.write(send); } }); From 6c488478d325304e6376ff3e8de8688cae0b0347 Mon Sep 17 00:00:00 2001 From: Evgeny Copisoff Date: Wed, 12 Jul 2017 10:48:35 +0300 Subject: [PATCH 3/3] On websocket connection create correct error object by specification. --- src/connection.js | 4 +++- src/error.js | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/connection.js b/src/connection.js index 201dc2f..1829615 100644 --- a/src/connection.js +++ b/src/connection.js @@ -101,7 +101,9 @@ module.exports = function (classes){ } if (err) { - err = err.toString(); + //err = err.toString(); + //by specification need object with fields 'message' and code + err = err.getObject(); result = null; } else { EventEmitter.trace('-->', 'Response (id ' + msg.id + '): ' + diff --git a/src/error.js b/src/error.js index 9b92d5e..216a6d3 100644 --- a/src/error.js +++ b/src/error.js @@ -16,6 +16,10 @@ module.exports = function (classes){ }, toString: function(){ return this.message; + }, + getObject: function(){ + let {code = 0, message = ''} = this; + return {code, message}; } }).$inherit(Error, []);