@@ -120,10 +120,6 @@ function Client (options) {
120
120
121
121
this . log = options . log . child ( { clazz : 'Client' } , true )
122
122
123
- this . on ( 'error' , function ( err ) {
124
- self . cb ( err )
125
- } )
126
-
127
123
this . timeout = parseInt ( ( options . timeout || 0 ) , 10 )
128
124
this . connectTimeout = parseInt ( ( options . connectTimeout || 0 ) , 10 )
129
125
this . idleTimeout = parseInt ( ( options . idleTimeout || 0 ) , 10 )
@@ -172,18 +168,6 @@ function Client (options) {
172
168
util . inherits ( Client , EventEmitter )
173
169
module . exports = Client
174
170
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
- this . log . error ( 'Caught exception:' , err )
182
- } else {
183
- this . log . info ( 'Unhandled output:' , ret )
184
- }
185
- }
186
-
187
171
/**
188
172
* Sends an abandon request to the LDAP server.
189
173
*
@@ -298,13 +282,15 @@ Client.prototype.bind = function bind (name,
298
282
controls : controls
299
283
} )
300
284
285
+ // While we are binding to the server, register the callback as error handler
301
286
var self = this
302
- this . cb = function ( err , ret ) {
303
- delete self . cb
287
+ function callbackWrapper ( err , ret ) {
288
+ self . removeListener ( 'error' , callbackWrapper )
304
289
callback ( err , ret )
305
290
}
291
+ this . addListener ( 'error' , callbackWrapper )
306
292
307
- return this . _send ( req , [ errors . LDAP_SUCCESS ] , null , callback , _bypass )
293
+ return this . _send ( req , [ errors . LDAP_SUCCESS ] , null , callbackWrapper , _bypass )
308
294
}
309
295
310
296
/**
0 commit comments