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