USING TRY-CATCH BLOCK
app.post("/listings", async (req, res,next) => {
try {
const newListing = new Listing(req.body.listing);
await newListing.save();
res.redirect("/listings");
} catch (err) {
next(err);
}
});app.use((err,req, res, next) => {
res.send("error occured");
Comments
Post a Comment