check page length before return in nextInTag (#173)

fixes #172

Reviewed-on: https://codeberg.org/rimgo/rimgo/pulls/173
Co-authored-by: orangix <uleo8b8g@anonaddy.me>
Co-committed-by: orangix <uleo8b8g@anonaddy.me>
This commit is contained in:
orangix 2024-02-07 01:13:29 +00:00 committed by video-prize-ranch
parent 337796b9be
commit 09a76779c9
1 changed files with 2 additions and 1 deletions

View File

@ -24,7 +24,8 @@ func nextInTag(client *api.Client, tagname, sort, page, I string) string {
if i >= len(tag.Posts)-1 {
pageNumber, _ := strconv.Atoi(page)
tagn, err := client.FetchTag(tagname, sort, strconv.Itoa(pageNumber+1))
if err != nil {
// Check length - Imgur will not return an error if there are no more posts and you request the next page
if err != nil || len(tagn.Posts) < 1 {
return ""
}
return tagn.Posts[0].Link