all repos — artbound-go @ 79e63cd2787ece34f59ee8d885803aefcccf2945

The official administration panel for ArtBound, by EarthBound Café.

minor bug fix
Marco Andronaco andronacomarco@gmail.com
Fri, 22 Dec 2023 14:44:27 +0100
commit

79e63cd2787ece34f59ee8d885803aefcccf2945

parent

d98670b07f40b6c4a1e88f4c62d2f0be6c39b8ac

1 files changed, 11 insertions(+), 3 deletions(-)

jump to
M artbound.goartbound.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) } }