From 47fc5afc6200059c72f13bca2bcdf1421e3607b3 Mon Sep 17 00:00:00 2001 From: Akmal Date: Sat, 6 Jul 2024 20:15:35 +0700 Subject: [PATCH] Return err on all handler when error --- handlers/grid.go | 2 +- handlers/images.go | 6 +++--- handlers/videos.go | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/handlers/grid.go b/handlers/grid.go index a3fc48f..8545775 100644 --- a/handlers/grid.go +++ b/handlers/grid.go @@ -138,7 +138,7 @@ func Grid() fiber.Handler { item, err := scraper.GetData(postID) if err != nil { - return c.SendStatus(fiber.StatusInternalServerError) + return err } if len(item.Medias) == 1 { diff --git a/handlers/images.go b/handlers/images.go index b6fc75b..6817e7f 100644 --- a/handlers/images.go +++ b/handlers/images.go @@ -11,17 +11,17 @@ func Images() fiber.Handler { postID := c.Params("postID") mediaNum, err := c.ParamsInt("mediaNum", 1) if err != nil { - return c.SendStatus(fiber.StatusNotFound) + return err } item, err := scraper.GetData(postID) if err != nil { - return c.SendStatus(fiber.StatusNotFound) + return err } // Redirect to image URL if mediaNum > len(item.Medias) { - return c.SendStatus(fiber.StatusNotFound) + return err } imageURL := item.Medias[max(1, mediaNum)-1].URL return c.Redirect(imageURL, fiber.StatusFound) diff --git a/handlers/videos.go b/handlers/videos.go index 1da3f56..d7e7330 100644 --- a/handlers/videos.go +++ b/handlers/videos.go @@ -12,17 +12,17 @@ func Videos() fiber.Handler { postID := c.Params("postID") mediaNum, err := c.ParamsInt("mediaNum", 1) if err != nil { - return c.SendStatus(fiber.StatusInternalServerError) + return err } item, err := scraper.GetData(postID) if err != nil { - return c.SendStatus(fiber.StatusInternalServerError) + return err } // Redirect to image URL if mediaNum > len(item.Medias) { - return c.SendStatus(fiber.StatusNotFound) + return err } videoURL := item.Medias[max(1, mediaNum)-1].URL