From 135045b7d0d3f8e0346e5fccb148b7fcdd9090da Mon Sep 17 00:00:00 2001 From: jm20122012 Date: Wed, 3 Jul 2024 14:29:00 -0600 Subject: [PATCH] Fixed issue with not checking error return --- controller/internal/api/api.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/controller/internal/api/api.go b/controller/internal/api/api.go index 00f736e..ac2d7f3 100644 --- a/controller/internal/api/api.go +++ b/controller/internal/api/api.go @@ -70,8 +70,12 @@ func pingHandler(w http.ResponseWriter, r *http.Request) { "ping": "OK", } w.Header().Set("Content-Type", "application/json") - w.WriteHeader(http.StatusOK) - json.NewEncoder(w).Encode(resp) + err := json.NewEncoder(w).Encode(resp) + if err != nil { + w.WriteHeader(http.StatusInternalServerError) + } else { + w.WriteHeader(http.StatusOK) + } } func getSystemStatus(w http.ResponseWriter, r *http.Request) { @@ -89,6 +93,10 @@ func getSystemStatus(w http.ResponseWriter, r *http.Request) { } w.Header().Set("Content-Type", "application-json") - w.WriteHeader(http.StatusOK) - json.NewEncoder(w).Encode(resp) + err := json.NewEncoder(w).Encode(resp) + if err != nil { + w.WriteHeader(http.StatusInternalServerError) + } else { + w.WriteHeader(http.StatusOK) + } }