Skip to content

Commit

Permalink
fix: skip error handlers if no error
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Jun 27, 2016
1 parent 85332d9 commit 0eb3a44
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
6 changes: 6 additions & 0 deletions index.js
Expand Up @@ -149,6 +149,12 @@ Kareem.prototype.execPost = function(name, context, args, options, callback) {
next();
}
} else {
if (post.length === args.length + 2) {
if (++currentPost >= numPosts) {
return callback.apply(null, [null].concat(args));
}
next();
}
if (post.length === args.length + 1) {
post.apply(context, args.concat(function(error) {
if (error) {
Expand Down
21 changes: 21 additions & 0 deletions test/wrap.test.js
Expand Up @@ -174,6 +174,27 @@ describe('wrap()', function() {
{ useErrorHandlers: true });
});

it('error handlers with no error', function(done) {
hooks.post('cook', function(error, callback) {
callback(new Error('another error occurred'));
});

var args = [];
args.push(function(error) {
assert.ifError(error);
done();
});

hooks.wrap(
'cook',
function(callback) {
callback();
},
null,
args,
{ useErrorHandlers: true });
});

it('works with no args', function(done) {
hooks.pre('cook', function(done) {
done();
Expand Down

0 comments on commit 0eb3a44

Please sign in to comment.