Add resultError event to client

Detecting certain types of errors in encountered during any operation
(such as BusyError or UnavailableError) can be useful for making
client-wide decisions.
This commit is contained in:
Patrick Mooney 2014-07-23 14:44:15 -05:00
parent 0133e65865
commit 8fd16ee255
3 changed files with 39 additions and 0 deletions

View File

@ -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

View File

@ -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.

View File

@ -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);