Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/remote-objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -677,14 +677,14 @@ RemoteObjects.prototype.invokeMethodInContext = function(ctx, method, cb) {
'Pass the method as ctx.method instead.');
}

self.phases.run(ctx, triggerErrorAndCallBack);
self.phases.run(ctx, function interceptInvocationErrors(err) {
if (!err) return cb();

function triggerErrorAndCallBack(err) {
ctx.error = err;
self.execHooks('afterError', method, scope, ctx, function(hookErr) {
cb(hookErr || err);
});
}
});
};

/**
Expand Down
18 changes: 18 additions & 0 deletions test/rest.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2730,6 +2730,24 @@ describe('strong-remoting-rest', function() {
});
});

it('is not called on success', function(done) {
var hookCalled = false;
var method = givenSharedStaticMethod(function(cb) {
cb();
});

objects.afterError(method.name, function(ctx, next) {
hookCalled = true;
next();
});

json(method.url).end(function(err) {
if (err) return done(err);
expect(hookCalled, 'hookCalled').to.equal(false);
done();
});
});

function verifyErrorHookIsCalled(method, expectedError, done) {
var hookContext = 'hook not called';

Expand Down