Actually handle all possible errors while attempting to read comicinfo.xml.
This commit is contained in:
+29
-5
@@ -80,9 +80,22 @@ func Index(w http.ResponseWriter, r *http.Request) {
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
cib, _ := io.ReadAll(cif)
|
||||
_ = cif.Close()
|
||||
_ = xml.Unmarshal(cib, &ComicInfo)
|
||||
|
||||
cib, err := io.ReadAll(cif)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
err = cif.Close()
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
err = xml.Unmarshal(cib, &ComicInfo)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
c.Set(path, ComicInfo, cache.NoExpiration)
|
||||
}
|
||||
}
|
||||
@@ -132,10 +145,21 @@ func Index(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
err = defaults.Set(&feed)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
data, err := xml.MarshalIndent(feed, "", " ")
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
_ = defaults.Set(&feed)
|
||||
data, _ := xml.MarshalIndent(feed, "", " ")
|
||||
http.ServeContent(w, r, "feed.xml", time.Now(), bytes.NewReader(data))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user