Skip to content
This repository was archived by the owner on May 14, 2024. It is now read-only.

Commit 79f3625

Browse files
Matthew NakamaTPXP
authored andcommitted
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.
1 parent 0ccbec6 commit 79f3625

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

lib/client/client.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ function Client (options) {
120120

121121
this.log = options.log.child({ clazz: 'Client' }, true)
122122

123+
this.on('error', function(err) {
124+
self.cb(err);
125+
})
126+
123127
this.timeout = parseInt((options.timeout || 0), 10)
124128
this.connectTimeout = parseInt((options.connectTimeout || 0), 10)
125129
this.idleTimeout = parseInt((options.idleTimeout || 0), 10)
@@ -168,6 +172,18 @@ function Client (options) {
168172
util.inherits(Client, EventEmitter)
169173
module.exports = Client
170174

175+
/**
176+
* Default handler for error callbacks when
177+
* one isn't set in the instance
178+
*/
179+
Client.prototype.cb = function(err, ret) {
180+
if (err) {
181+
console.error('Caught exception:', err)
182+
} else {
183+
console.log('Unhandled output:', ret)
184+
}
185+
}
186+
171187
/**
172188
* Sends an abandon request to the LDAP server.
173189
*
@@ -282,6 +298,12 @@ Client.prototype.bind = function bind (name,
282298
controls: controls
283299
})
284300

301+
var self = this
302+
this.cb = function(err, ret) {
303+
delete self.cb
304+
callback(err, ret)
305+
}
306+
285307
return this._send(req, [errors.LDAP_SUCCESS], null, callback, _bypass)
286308
}
287309

0 commit comments

Comments
 (0)