From 79e63cd2787ece34f59ee8d885803aefcccf2945 Mon Sep 17 00:00:00 2001 From: Marco Andronaco Date: Fri, 22 Dec 2023 14:44:27 +0100 Subject: [PATCH] minor bug fix --- artbound.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/artbound.go b/artbound.go index 22d6e62..fb92ecf 100644 --- a/artbound.go +++ b/artbound.go @@ -91,21 +91,29 @@ func getHandler(db *cache.DB) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { u, err := url.Parse(r.URL.String()) if err != nil { - log.Fatal("Could not parse URL.") + log.Println("Could not parse URL.") http.Error(w, err.Error(), http.StatusInternalServerError) return } month := u.Query().Get("month") + if month == "" { + http.Error(w, "\"month\" parameter is required.", http.StatusBadRequest) + return + } entries, err := db.GetEntries(month) if err != nil { - log.Fatal("Could not get entries for month", month) - http.Error(w, err.Error(), http.StatusInternalServerError) + http.Error(w, "Could not get entries.", http.StatusInternalServerError) return } w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusCreated) + + if len(entries) == 0 { + w.Write([]byte("[]")) + return + } json.NewEncoder(w).Encode(entries) } }