From 3d5f4a773d561726b3abb4fd23cb6eeb99338d81 Mon Sep 17 00:00:00 2001 From: tigerbot Date: Fri, 28 Apr 2017 14:19:56 -0600 Subject: [PATCH] implemented sending of errors not directly from requests --- wstunneld.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/wstunneld.js b/wstunneld.js index 0ae16ca..d188ce5 100644 --- a/wstunneld.js +++ b/wstunneld.js @@ -182,7 +182,7 @@ module.exports.create = function (copts) { if (firstToken) { var err = addToken(firstToken); if (err) { - ws.send(JSON.stringify({ error: err })); + ws.send(packer.pack(null, [0, err], 'control')); ws.close(); return; } @@ -210,7 +210,9 @@ module.exports.create = function (copts) { cmd = JSON.parse(opts.data.toString()); } catch (err) {} if (!Array.isArray(cmd) || typeof cmd[0] !== 'number') { - console.warn('received bad command "' + opts.data.toString() + '"'); + var msg = 'received bad command "' + opts.data.toString() + '"'; + console.warn(msg, 'from websocket', socketId); + ws.send(packer.pack(null, [0, {message: msg, code: 'E_BAD_COMMAND'}], 'control')); return; } @@ -227,6 +229,11 @@ module.exports.create = function (copts) { return; } + if (cmd[0] === 0) { + console.warn('received dis-associated error from', socketId, cmd[1]); + return; + } + if (commandHandlers[cmd[1]]) { err = commandHandlers[cmd[1]].apply(null, cmd.slice(2)); }