March 2018
Intermediate to advanced
592 pages
13h 44m
English
Next up, we're going to make that query Todo.findById. Here we're going to pass in the ID, which we have in the id variable, and then we're going to attach our success and error handlers, .then, passing in our success callback. This is going to get called potentially with the individual Todo document, and I am going to call catch as well, getting the error. We can do the error handler first. If there is an error, we're going to keep things really simple, res.status, setting it equal to 400, then we're going to go ahead and call send, leaving out the error object intentionally:
Todo.findById(id).then((todo) => {
}).catch((e) => {
res.status(400).send();
});
With this in place the only thing left to do is ...