diff --git a/lib/index.js b/lib/index.js index ec4a50a..44c5903 100644 --- a/lib/index.js +++ b/lib/index.js @@ -50,7 +50,11 @@ Odoo.prototype.connect = function (cb) { }); res.on('end', function () { - response = JSON.parse(response); + try { + response = JSON.parse(response); + } catch (err) { + return cb(err, null); + } if (response.error) { return cb(response.error, null); @@ -65,6 +69,10 @@ Odoo.prototype.connect = function (cb) { }); }); + req.on('error',function (err) { + return cb(err, null); + }); + req.write(json); };