From 4092fdba6f428f0868b7c5200abf430b7b8a6304 Mon Sep 17 00:00:00 2001 From: saji Date: Thu, 29 Feb 2024 13:11:49 -0600 Subject: [PATCH] [skip ci] return errors in http api --- http.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/http.go b/http.go index 4aa6f5c..3f35668 100644 --- a/http.go +++ b/http.go @@ -161,8 +161,8 @@ func apiV1GetValues(db *db.TelemDb) http.HandlerFunc { if startString != "" { start, err = time.Parse(time.RFC3339, startString) if err != nil { - // error out - panic("hi") + http.Error(w, "error getting values", http.StatusInternalServerError) + return } } end := time.Now().Add(1 * time.Hour) @@ -170,7 +170,8 @@ func apiV1GetValues(db *db.TelemDb) http.HandlerFunc { if endParam != "" { end, err = time.Parse(time.RFC3339, endParam) if err != nil { - panic("hi") + http.Error(w, "error getting values", http.StatusInternalServerError) + return } } name := chi.URLParam(r, "name") @@ -181,11 +182,13 @@ func apiV1GetValues(db *db.TelemDb) http.HandlerFunc { res, err := db.GetValues(r.Context(), name, field, start, end) if err != nil { // 500 server error: - fmt.Print(err) + http.Error(w, "error getting values", http.StatusInternalServerError) + return } b, err := json.Marshal(res) if err != nil { - panic(err) + http.Error(w, "error getting values", http.StatusInternalServerError) + return } w.Write(b) }