-
Notifications
You must be signed in to change notification settings - Fork 62
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
Promise hell #33
Comments
For example, const update = (req, res, next) => {
let search = { _id: req.params.id, _owner: req.currentUser._id };
Example.findOne(search)
.then(example => {
if (!example) {
return next();
}
delete req.body._owner; // disallow owner reassignment.
return example.update(req.body.example)
})
.then(() => res.sendStatus(200));
.catch(err => next(err));
}; |
I believe this refactoring introduces a bug as it may call |
Agreed. I'd like to get our of the promise nesting if possible, but this isn't the right way to do it. =/ |
This was referenced Mar 2, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Remove
then
s withinthen
s in example controller. Best practice for promises is not nesting thens. The return value from the previous then will be passed to the following one if information needs to be passed on.The text was updated successfully, but these errors were encountered: