extra error checking

This commit is contained in:
stryan 2023-03-20 11:40:07 -04:00
parent 9c68067fc3
commit 80adf6214e

View File

@ -51,7 +51,11 @@ func getNewestPost(subreddit string) (post, error) {
if len(resp.Data.Children) < 1 {
return post{}, errors.New("bad data from reddit")
}
numS := re.FindStringSubmatch(resp.Data.Children[0].Data.Title)[0]
reSearch := re.FindStringSubmatch(resp.Data.Children[0].Data.Title)
if len(reSearch) == 0 {
return post{}, fmt.Errorf("Something strange in data from reddit")
}
numS := reSearch[0]
num, err := strconv.Atoi(numS)
if err != nil || numS == "" {
num = -1