Skip to content

Commit

Permalink
Return err on all handler when error
Browse files Browse the repository at this point in the history
  • Loading branch information
Wikidepia committed Jul 6, 2024
1 parent 72054da commit 47fc5af
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion handlers/grid.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions handlers/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions handlers/videos.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 47fc5af

Please sign in to comment.