forked from AlexisReverte/node-odoo
-
Notifications
You must be signed in to change notification settings - Fork 16
Open
Description
There are no connect error handling:
when i try to connect to the wrong odoo server:
var Odoo = require('odoo');
var odoo = new Odoo({
host: '192.168.1.1',
database: 'database',
username: 'username',
password: 'password'
});
try {
odoo.connect(function (err) {
if (err) { return console.log('connect handle error: ',err); }
});
} catch (err) {
console.log('connect error: ',err)
}
i've got error:
events.js:141
throw er; // Unhandled 'error' event
^
Error: connect ETIMEDOUT 192.168.1.1:80
at Object.exports._errnoException (util.js:856:11)
at exports._exceptionWithHostPort (util.js:879:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1062:14)
[Finished in 21.7s with exit code 1]
I don't know what does if (err) {...}
must to handle, but it don't do it well
As you see, this error can't be handled by try {} catch (e) {}
construction. There is open issue about it. But i think it wont be close shortly.
Based on comments to issue i linked above, I make a handler. Adding this code:
req.on('error',function (err) {
cb(err)
});
to Odoo.prototype.connect
function.
In result - code i've wrote above, logging error instaed of throwing it:
connect handle error: { [Error: connect ETIMEDOUT 192.168.1.1:80]
code: 'ETIMEDOUT',
errno: 'ETIMEDOUT',
syscall: 'connect',
address: '192.168.1.1',
port: 80 }
Metadata
Metadata
Assignees
Labels
No labels