i using node.js, bluebird , redis. given:
redisclient.hmsetasync([key, 'sn', sn, 'make', make]) .then(redisclient.setasync(key + ":radio", radioarray)) .then(tmatic.send(res, 200)) .catch(function (e) { console.log("error reading file", e); tmatic.send(res, 500); });
when "radioarray" empty, redis throws exception:
unhandled rejection error: err wrong number of arguments command
this code sends 200 response back. whey doesn't hit .catch() method , throw 500?
answer! after hacking half hour, came this. macareno.marco!
redisclient.hmsetasync([key, 'sn', sn, 'make', make]) .then(function saveradios() { if (radioarray.length) { console.log("radio"); return redisclient.setasync(key + ":radio", radioarray) } }) .then(function () { tmatic.send(res, 200); }) .catch(function (e) { console.log("error:", e); tmatic.fail(e, res); });
when using line:
.then(tmatic.send(res, 200))
parameter being evaluated, , waiting function returned bluebird may call it. should use function instead, so:
.then(function(res) { tmatic.send(res, 200); }
Comments
Post a Comment