handle missing feeds

This commit is contained in:
Nazar Kanaev
2020-08-16 13:36:40 +01:00
parent 6df66afe44
commit 6bb7bf4157
2 changed files with 7 additions and 2 deletions

View File

@@ -176,10 +176,13 @@ func FeedListHandler(rw http.ResponseWriter, req *http.Request) {
res, err := http.Get(feedUrl)
if err != nil {
handler(req).log.Print(err)
rw.WriteHeader(http.StatusBadRequest)
writeJSON(rw, map[string]string{"status": "notfound"})
return
} else if res.StatusCode != 200 {
rw.WriteHeader(http.StatusBadRequest)
handler(req).log.Printf("Failed to fetch %s (status: %d)", feedUrl, res.StatusCode)
body, err := ioutil.ReadAll(res.Body)
handler(req).log.Print(string(body), err)
writeJSON(rw, map[string]string{"status": "notfound"})
return
}