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