diff --git a/reddit.go b/reddit.go index 7741c2b..2cb5938 100644 --- a/reddit.go +++ b/reddit.go @@ -3,6 +3,7 @@ package main import ( "crypto/tls" "encoding/json" + "errors" "fmt" "io/ioutil" "net/http" @@ -47,6 +48,9 @@ func getNewestPost(subreddit string) (post, error) { if err != nil { return post{}, err } + if len(resp.Data.Children) < 1 { + return post{}, errors.New("bad data from reddit") + } numS := re.FindStringSubmatch(resp.Data.Children[0].Data.Title)[0] num, err := strconv.Atoi(numS) if err != nil || numS == "" {