Wednesday, 13 December 2017

Beginners question about using promise (error handling)

I am using knex in my first node app. Knex return a promise. I try to understand how to handle my errors. I think I have looked at too many videos and read too many articles that have not quite related to my project which has got me a bit overwhelmed and confused.Say we have this very basic code that get comments from my db.router.get('/comments', (req, res) => { queries.comments() .then(comments => { res.render('comments', ({ comments: comments })) .catch(err => console.error('Error getting comments', err)) }); }); Would this be a basic but correct way catching the error from the query? If there would be an error what would the argument err be, that confuses me and I am not sure how to test it easily? Where does it come from. Would it return something like "No records found" or similar?Would appreciate to if someone could point out the obvious =)

Submitted December 13, 2017 at 08:44PM by geoholic

No comments:

Post a Comment