From 306ddb2b53d0d5f2222786e1ad96b3fba2fb3749 Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Wed, 30 Mar 2022 20:20:30 +0400 Subject: [PATCH] Error logging for last played songs. --- internal/handlers/handlers.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/internal/handlers/handlers.go b/internal/handlers/handlers.go index 3fa2ddf..9c5e7f7 100644 --- a/internal/handlers/handlers.go +++ b/internal/handlers/handlers.go @@ -59,11 +59,16 @@ func (h *RadioHandlers) Index(w http.ResponseWriter, r *http.Request) { return } + songs, err := radio.IcecastLastPlayedSongs(h.conf.ListLastNSongs, + h.conf.Icecast.Playlist) + if err != nil { + h.logErr.Println("cannot retrieve last songs:", err) + } + if err := compiledTemplates["index"].Execute(w, &IndexData{ MainSite: utils.MainSite(r.Host), Status: status, - Songs: radio.IcecastLastPlayedSongs(h.conf.ListLastNSongs, - h.conf.Icecast.Playlist), + Songs: songs, }); err != nil { h.logErr.Fatalln("failed to execute Index template:", err) http.Error(w, "cannot execute Index template", http.StatusInternalServerError) @@ -82,7 +87,11 @@ func (h *RadioHandlers) Stats(w http.ResponseWriter, _ *http.Request) { } func (h *RadioHandlers) LastSong(w http.ResponseWriter, _ *http.Request) { - songs := radio.IcecastLastPlayedSongs(1, h.conf.Icecast.Playlist) + songs, err := radio.IcecastLastPlayedSongs(1, h.conf.Icecast.Playlist) + if err != nil { + h.logErr.Println("cannot retrieve last songs:", err) + } + if len(songs) == 0 { w.WriteHeader(http.StatusNotFound) return