Add error handler for product page

This commit is contained in:
Moe Poi ~ 2021-11-21 08:46:39 +07:00
parent f209037436
commit 43e8497d67

View file

@ -180,14 +180,19 @@ router.get("/products", (req, res) => {
}); });
}); });
router.get("/product/:id", (req, res) => { router.get(["/product", "/product/:id"], (req, res) => {
if (!req.params.id) {
auth.session_converter(req.cookies.session_token).then((key) => { auth.session_converter(req.cookies.session_token).then((key) => {
if (key != null) { if (key != null) {
controller.getProduct(req.params.id).then((data) => { controller.getProduct(req.params.id).then((data) => {
if (data != undefined) {
res.render("pages/product", { res.render("pages/product", {
data: data, data: data,
loggedIn: 'true' loggedIn: 'true'
}); });
} else {
res.redirect("/products");
}
}); });
} else { } else {
controller.getProduct(req.params.id).then((data) => { controller.getProduct(req.params.id).then((data) => {
@ -198,6 +203,9 @@ router.get("/product/:id", (req, res) => {
}); });
} }
}); });
} else {
res.redirect("/products")
}
}); });
router.get("/bag", (req, res) => { router.get("/bag", (req, res) => {