From 0be444aa295ae76b3eb3d6ee8ada5da6ff702f7b Mon Sep 17 00:00:00 2001 From: Peter Stuifzand Date: Sun, 22 Dec 2019 11:32:31 +0100 Subject: [PATCH] Clean up error handling of getEntriesForFeed --- main.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index 326504e..6f64795 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,7 @@ package main import ( + "fmt" "html/template" "log" "net/http" @@ -21,7 +22,10 @@ func main() { log.Fatal(err) } - items := getEntriesForFeed(u) + items, err := getEntriesForFeed(u) + if err != nil { + log.Fatal(err) + } items = filterEntriesAfter(items, now.With(time.Now()).Monday()) @@ -36,19 +40,19 @@ func main() { } } -func getEntriesForFeed(u *url.URL) []microsub.Item { +func getEntriesForFeed(u *url.URL) ([]microsub.Item, error) { resp, err := http.Get(u.String()) if err != nil { - log.Fatal(err) + return nil, err } defer resp.Body.Close() if resp.StatusCode != 200 { - log.Fatalf("Status is not 200, but %d", resp.StatusCode) + return nil, fmt.Errorf("status is not 200, but %d", resp.StatusCode) } md := microformats.Parse(resp.Body, u) items := jf2.SimplifyMicroformatDataItems(md) - return items + return items, nil } func filterEntriesAfter(items []microsub.Item, from time.Time) []microsub.Item {