Catch block only checks 422 validation error
novaknole opened this issue · comments
Giorgi Lagidze commented
Hello. Here is code I found in your project.
try {
yield article.uploadAndSave(req.file);
req.flash('success', 'Successfully created article!');
res.redirect(`/articles/${article._id}`);
} catch (err) {
res.status(422).render('articles/new', {
title: article.title || 'New Article',
errors: [err.toString()],
article
});
}
So, the problem I see is that let's save uploadAndSave method throws an exception , but it's not 422 validation error. What this code will do is that even though thrown error is not 422, it will think it is 422 and redirect to articles/new url. I think this is not the best way and might be wrong.
madhums commented
Yes, you might be right. The error handling can be more informative BUT this is just a demo application. Feel free to customise as per your use case.