[skip ci] return errors in http api
All checks were successful
Go / build (1.21) (push) Successful in 1m17s
Go / build (1.22) (push) Successful in 1m18s

This commit is contained in:
saji 2024-02-29 13:11:49 -06:00
parent 19b337a84b
commit 4092fdba6f

13
http.go
View file

@ -161,8 +161,8 @@ func apiV1GetValues(db *db.TelemDb) http.HandlerFunc {
if startString != "" { if startString != "" {
start, err = time.Parse(time.RFC3339, startString) start, err = time.Parse(time.RFC3339, startString)
if err != nil { if err != nil {
// error out http.Error(w, "error getting values", http.StatusInternalServerError)
panic("hi") return
} }
} }
end := time.Now().Add(1 * time.Hour) end := time.Now().Add(1 * time.Hour)
@ -170,7 +170,8 @@ func apiV1GetValues(db *db.TelemDb) http.HandlerFunc {
if endParam != "" { if endParam != "" {
end, err = time.Parse(time.RFC3339, endParam) end, err = time.Parse(time.RFC3339, endParam)
if err != nil { if err != nil {
panic("hi") http.Error(w, "error getting values", http.StatusInternalServerError)
return
} }
} }
name := chi.URLParam(r, "name") 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) res, err := db.GetValues(r.Context(), name, field, start, end)
if err != nil { if err != nil {
// 500 server error: // 500 server error:
fmt.Print(err) http.Error(w, "error getting values", http.StatusInternalServerError)
return
} }
b, err := json.Marshal(res) b, err := json.Marshal(res)
if err != nil { if err != nil {
panic(err) http.Error(w, "error getting values", http.StatusInternalServerError)
return
} }
w.Write(b) w.Write(b)
} }