fix: check ignored errors
This commit is contained in:
parent
a5bc03959e
commit
dccfd17bcc
@ -45,30 +45,33 @@ type Artist struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
func (a *Album) parseAlbumData(doc *goquery.Document) {
|
||||
func (a *Album) parseAlbumData(doc *goquery.Document) error {
|
||||
pageMetadata, exists := doc.Find("meta[itemprop='page_data']").Attr("content")
|
||||
if !exists {
|
||||
return
|
||||
return nil
|
||||
}
|
||||
|
||||
var albumMetadataFromPage albumMetadata
|
||||
json.Unmarshal([]byte(pageMetadata), &albumMetadataFromPage)
|
||||
if err := json.Unmarshal([]byte(pageMetadata), &albumMetadataFromPage); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
albumData := albumMetadataFromPage.Album
|
||||
a.Artist = albumData.Artist.Name
|
||||
a.Name = albumData.Name
|
||||
a.Image = albumData.Image
|
||||
a.About[0] = albumData.Description
|
||||
//a.About[1] = truncateText(albumData.Description)
|
||||
a.About[1] = truncateText(albumData.Description)
|
||||
a.About[1] = ""
|
||||
|
||||
for _, track := range albumMetadataFromPage.AlbumAppearances {
|
||||
url := strings.Replace(track.Song.Url, "https://genius.com", "", -1)
|
||||
a.Tracks = append(a.Tracks, Track{Title: track.Song.Title, Url: url})
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *Album) Parse(doc *goquery.Document) {
|
||||
a.parseAlbumData(doc)
|
||||
func (a *Album) Parse(doc *goquery.Document) error {
|
||||
return a.parseAlbumData(doc)
|
||||
}
|
||||
|
||||
|
@ -58,10 +58,14 @@ func Album(l *logrus.Logger) http.HandlerFunc {
|
||||
}
|
||||
|
||||
var a data.Album
|
||||
a.Parse(doc)
|
||||
if err = a.Parse(doc); err != nil {
|
||||
l.Error(err)
|
||||
}
|
||||
|
||||
views.AlbumPage(a).Render(context.Background(), w)
|
||||
|
||||
setCache(id, a)
|
||||
if err = setCache(id, a); err != nil {
|
||||
l.Errorln(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -85,9 +85,11 @@ func Annotations(l *logrus.Logger) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
setCache(id, body)
|
||||
_, err = w.Write(response)
|
||||
if err != nil {
|
||||
if err = setCache(id, body); err != nil {
|
||||
l.Errorln(err)
|
||||
}
|
||||
|
||||
if _, err = w.Write(response); err != nil {
|
||||
l.Errorln("Error sending response: ", err)
|
||||
}
|
||||
}
|
||||
|
@ -57,6 +57,8 @@ func Lyrics(l *logrus.Logger) http.HandlerFunc {
|
||||
s.Parse(doc)
|
||||
|
||||
views.LyricsPage(s).Render(context.Background(), w)
|
||||
setCache(id, s)
|
||||
if err = setCache(id, s); err != nil {
|
||||
l.Errorln(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -53,6 +53,8 @@ func ImageProxy(l *logrus.Logger) http.HandlerFunc {
|
||||
}
|
||||
|
||||
w.Header().Add("Content-type", fmt.Sprintf("image/%s", ext))
|
||||
io.Copy(w, res.Body)
|
||||
if _, err = io.Copy(w, res.Body); err != nil {
|
||||
l.Errorln("unable to write image", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +30,11 @@ func Search(l *logrus.Logger) http.HandlerFunc {
|
||||
var sRes data.SearchResponse
|
||||
|
||||
d := json.NewDecoder(res.Body)
|
||||
d.Decode(&sRes)
|
||||
if err = d.Decode(&sRes); err != nil {
|
||||
l.Errorln(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
views.ErrorPage(500, "something went wrong").Render(context.Background(), w)
|
||||
}
|
||||
|
||||
results := data.SearchResults{Query: query, Sections: sRes.Response.Sections}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user