I am facing an issue where my app crashes when mongoose is unable to find the item. I want to display a 404 error page instead.
Here is the code snippet:
try {
let theBeverage = Product.findOne({ _id: beverageId });
await theBeverage.then((data) => (theBeverage = data));
res.render("menuetail.ejs", { theBeverage });
} catch (error) {
res.render("404.ejs").status(404);
}
I anticipate that it will show a 404 page in such cases.