diff --git a/CHANGES.md b/CHANGES.md index ca28948..9f152bd 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,7 @@ ## CURRENT +- Add 'resultError' event to client - Update paged search automation in client - Add Change.apply method for modifying objects - Update bunyan to 0.23.1 diff --git a/lib/client/client.js b/lib/client/client.js index 6720320..5d36213 100644 --- a/lib/client/client.js +++ b/lib/client/client.js @@ -1268,6 +1268,9 @@ Client.prototype._sendSocket = function _sendSocket(message, var sentEmitter = false; function _done(event, obj) { + if (event === 'error' && self.listeners('resultError')) { + self.emit('resultError', obj); + } if (emitter) { if (event === 'error') { // Error will go unhandled if emitter hasn't been sent via callback. diff --git a/test/client.test.js b/test/client.test.js index 6e5c208..14f6e89 100644 --- a/test/client.test.js +++ b/test/client.test.js @@ -227,6 +227,10 @@ test('setup', function (t) { return next(); }); + server.search('cn=busy', function (req, res, next) { + next(new ldap.BusyError('too much to do')); + }); + server.unbind(function (req, res, next) { res.end(); return next(); @@ -1051,6 +1055,37 @@ test('search timeout (GH-51)', function (t) { }); +test('resultError handling', function (t) { + t.plan(3); + vasync.pipeline({ + funcs: [ + function errSearch(_, cb) { + client.once('resultError', function (error) { + t.equal(error.name, 'BusyError'); + }); + client.search('cn=busy', {}, function (err, res) { + res.once('error', function (error) { + t.equal(error.name, 'BusyError'); + cb(); + }); + }); + }, + function cleanSearch(_, cb) { + client.on('resultError', t.ifError.bind(null)); + client.search(SUFFIX, {}, function (err, res) { + res.once('end', function () { + t.ok(true); + cb(); + }); + }); + } + ] + }, function (err, res) { + client.removeAllListeners('resultError'); + }); +}); + + test('unbind (GH-30)', function (t) { client.unbind(function (err) { t.ifError(err);