implemented sending of errors not directly from requests

This commit is contained in:
tigerbot 2017-04-28 14:19:56 -06:00
parent b4a300cc64
commit 3d5f4a773d
1 changed files with 9 additions and 2 deletions

View File

@ -182,7 +182,7 @@ module.exports.create = function (copts) {
if (firstToken) { if (firstToken) {
var err = addToken(firstToken); var err = addToken(firstToken);
if (err) { if (err) {
ws.send(JSON.stringify({ error: err })); ws.send(packer.pack(null, [0, err], 'control'));
ws.close(); ws.close();
return; return;
} }
@ -210,7 +210,9 @@ module.exports.create = function (copts) {
cmd = JSON.parse(opts.data.toString()); cmd = JSON.parse(opts.data.toString());
} catch (err) {} } catch (err) {}
if (!Array.isArray(cmd) || typeof cmd[0] !== 'number') { 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; return;
} }
@ -227,6 +229,11 @@ module.exports.create = function (copts) {
return; return;
} }
if (cmd[0] === 0) {
console.warn('received dis-associated error from', socketId, cmd[1]);
return;
}
if (commandHandlers[cmd[1]]) { if (commandHandlers[cmd[1]]) {
err = commandHandlers[cmd[1]].apply(null, cmd.slice(2)); err = commandHandlers[cmd[1]].apply(null, cmd.slice(2));
} }