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:
parent
0ccbec6adb
commit
79f3625f61
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue