Skip to content

Commit

Permalink
fix: make error handlers handle errors in pre hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Feb 3, 2017
1 parent ddc7aeb commit af38033
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 7 additions & 2 deletions index.js
Expand Up @@ -239,8 +239,13 @@ Kareem.prototype.wrap = function(name, fn, context, args, options) {

this.execPre(name, context, function(error) {
if (error) {
return _handleWrapError(_this, error, name, context, argsWithoutCb,
options, lastArg)
var numCallbackParams = options.numCallbackParams || 0;
var nulls = [];
for (var i = 0; i < numCallbackParams; ++i) {
nulls.push(null);
}
return _handleWrapError(_this, error, name, context, nulls,
options, lastArg);
}

var end = (typeof lastArg === 'function' ? args.length - 1 : args.length);
Expand Down
4 changes: 2 additions & 2 deletions test/wrap.test.js
Expand Up @@ -130,7 +130,7 @@ describe('wrap()', function() {
done(new Error('fail'));
});

hooks.post('cook', function(error, callback) {
hooks.post('cook', function(error, res, callback) {
callback(new Error('another error occurred'));
});

Expand All @@ -148,7 +148,7 @@ describe('wrap()', function() {
},
null,
args,
{ useErrorHandlers: true });
{ useErrorHandlers: true, numCallbackParams: 1 });
});

it('error handlers with no callback', function(done) {
Expand Down

0 comments on commit af38033

Please sign in to comment.