Skip to content

Commit

Permalink
fix: handle empty reddit.com API post body
Browse files Browse the repository at this point in the history
  • Loading branch information
CorentinB committed Sep 28, 2024
1 parent 7696762 commit 5c00f39
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions internal/pkg/crawl/sitespecific/reddit/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ func ExtractPost(body []byte) (permalinks []string, assets []string, err error)
return permalinks, assets, err
}

if len(data.Data.Children) == 0 {
return permalinks, assets, fmt.Errorf("no children found in post")
}

permalinks = append(permalinks, fmt.Sprintf("https://www.reddit.com%s", data.Data.Children[0].Data.Permalink), fmt.Sprintf("https://old.reddit.com%s", data.Data.Children[0].Data.Permalink))

assets, err = extractor.GetURLsFromJSON(body)
Expand Down

0 comments on commit 5c00f39

Please sign in to comment.