-
Notifications
You must be signed in to change notification settings - Fork 376
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Calling next(error) in hook does not bubble error up to initial orm call #301
Comments
From the wiki:
The |
I think maybe the wiki needs to be updated. This code works for me: afterLoad: function(next) {
console.log(next); // [Function]
// If I include this code then it (correctly) stops executing other hooks
//return next(new Error("after load error"));
next();
}, |
Ahh indeed the feature was added here. I had a play with the code and tried to make it work. Whilst I did get a test case with your use case passing, it broke other things inexplicably. I was going to atleast put up the test case, but it also broke mocha unexpectedly so... I'll let someone braver work on this one. It's jinxed and doesn't smell right. |
I'll take a look later today. |
Your problem is you're using In general, only |
I found that the same thing happened in afterLoad - if I define next but don't call it, it hangs (which is what I would expect). The use case for me is that I want to load some other stuff in afterAutoFetch(). For example I load a Channel object and auto-fetch the Users in that channel. In afterAutoFetch I set a user_ids property, which is a list of each user in the channel's id. When everything completes I convert select fields to json. eg: GET /channel/7
{
name: 'MyChannel',
user_ids: [1,6,3,7]
} If there's an error, I want to inform the client. eg db.Channel.get(7, function(err, channel) {
if(err) { return res.json({error: 'Could not load channel'}) }
res.json({name: channel.name, user_ids: channel.user_ids});
}) |
This should be possible for persisted models, however not for new ones ( It's a bit strange that we support passing a |
I can see what you're saying about not wanting to leave the model in an inconsistent state. On the other hand I feel that there needs to be some way for the caller to know if there was an error in |
I made some changes, I'm going to commit them now, just want to add a test case for this. |
Please test this latest commit. Please remember that in case of an error, the instance was already saved on database so you might want to do something about it. |
Ok thanks, I'll give it a try. |
It works for afterAutoFetch but not for afterLoad |
I actually tested for |
eg
The text was updated successfully, but these errors were encountered: