handle Client.emit('error') events

This prevents node crashes from Client.bind() and etc.
We set a callback handler in the instance during bind()
and send errors to it.
This commit is contained in:
Matthew Nakama 2017-04-28 11:42:11 -04:00 committed by Thomas P
parent 0ccbec6adb
commit 79f3625f61
No known key found for this signature in database
GPG Key ID: 722E1405F9F15F5E
1 changed files with 22 additions and 0 deletions

View File

@ -120,6 +120,10 @@ function Client (options) {
this.log = options.log.child({ clazz: 'Client' }, true)
this.on('error', function(err) {
self.cb(err);
})
this.timeout = parseInt((options.timeout || 0), 10)
this.connectTimeout = parseInt((options.connectTimeout || 0), 10)
this.idleTimeout = parseInt((options.idleTimeout || 0), 10)
@ -168,6 +172,18 @@ function Client (options) {
util.inherits(Client, EventEmitter)
module.exports = Client
/**
* Default handler for error callbacks when
* one isn't set in the instance
*/
Client.prototype.cb = function(err, ret) {
if (err) {
console.error('Caught exception:', err)
} else {
console.log('Unhandled output:', ret)
}
}
/**
* Sends an abandon request to the LDAP server.
*
@ -282,6 +298,12 @@ Client.prototype.bind = function bind (name,
controls: controls
})
var self = this
this.cb = function(err, ret) {
delete self.cb
callback(err, ret)
}
return this._send(req, [errors.LDAP_SUCCESS], null, callback, _bypass)
}