From 69988e11565102c03d02cdf720f89f9f2ba18eac Mon Sep 17 00:00:00 2001 From: monirzadeh <25131576+Monirzadeh@users.noreply.github.com> Date: Sat, 20 Jan 2024 00:00:53 +0330 Subject: [PATCH] add err handling for missing function --- album.go | 11 +++++++++-- annotations.go | 6 +++++- lyrics.go | 6 +++++- proxy.go | 6 +++++- search.go | 5 ++++- utils.go | 7 +++++-- 6 files changed, 33 insertions(+), 8 deletions(-) diff --git a/album.go b/album.go index e21d8a2..7f48982 100644 --- a/album.go +++ b/album.go @@ -55,7 +55,10 @@ func (a *album) parseAlbumData(doc *goquery.Document) { } var albumMetadataFromPage albumMetadata - json.Unmarshal([]byte(pageMetadata), &albumMetadataFromPage) + err := json.Unmarshal([]byte(pageMetadata), &albumMetadataFromPage) + if err != nil { + logger.Errorln(err) + } albumData := albumMetadataFromPage.Album a.Artist = albumData.Artist.Name @@ -135,5 +138,9 @@ func albumHandler(w http.ResponseWriter, r *http.Request) { render("album", w, a) - setCache(id, a) + err = setCache(id, a) + if err != nil { + logger.Errorln(err) + } + } diff --git a/annotations.go b/annotations.go index f77d35c..715c9ec 100644 --- a/annotations.go +++ b/annotations.go @@ -110,7 +110,11 @@ func annotationsHandler(w http.ResponseWriter, r *http.Request) { return } - setCache(id, body) + err = setCache(id, body) + if err != nil { + logger.Errorln(err) + } + _, err = w.Write(response) if err != nil { logger.Errorln("Error sending response: ", err) diff --git a/lyrics.go b/lyrics.go index 0fdcb8c..913844c 100644 --- a/lyrics.go +++ b/lyrics.go @@ -168,5 +168,9 @@ func lyricsHandler(w http.ResponseWriter, r *http.Request) { s.parse(doc) render("lyrics", w, s) - setCache(id, s) + err = setCache(id, s) + if err != nil { + logger.Errorln(err) + } + } diff --git a/proxy.go b/proxy.go index 006c932..bb7005a 100644 --- a/proxy.go +++ b/proxy.go @@ -69,5 +69,9 @@ func proxyHandler(w http.ResponseWriter, r *http.Request) { } w.Header().Add("Content-type", fmt.Sprintf("image/%s", ext)) - io.Copy(w, res.Body) + _, err = io.Copy(w, res.Body) + if err != nil { + logger.Errorln(err) + } + } diff --git a/search.go b/search.go index 1392e8d..cfd28ac 100644 --- a/search.go +++ b/search.go @@ -53,7 +53,10 @@ func searchHandler(w http.ResponseWriter, r *http.Request) { var data response d := json.NewDecoder(res.Body) - d.Decode(&data) + err = d.Decode(&data) + if err != nil { + logger.Errorln(err) + } vars := renderVars{query, data.Response.Sections} diff --git a/utils.go b/utils.go index 94a686a..a7ccc8a 100644 --- a/utils.go +++ b/utils.go @@ -42,7 +42,11 @@ func getCache(key string) (interface{}, error) { func write(w http.ResponseWriter, status int, data []byte) { w.WriteHeader(status) - w.Write(data) + _, err := w.Write(data) + if err != nil { + logger.Errorln(err) + } + } func securityHeaders(next http.Handler) http.Handler { @@ -105,7 +109,6 @@ func sendRequest(u string) (*http.Response, error) { return nil, err } - req := &http.Request{ Method: http.MethodGet, URL: url,