From a0feeebff658b25dc412049247548276ab964ef5 Mon Sep 17 00:00:00 2001 From: Roman Zipp Date: Mon, 14 Feb 2022 14:18:00 +0100 Subject: [PATCH] Add controller error writer exception handling --- controllers/controllers.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/controllers/controllers.go b/controllers/controllers.go index 252fa5b..7adb041 100644 --- a/controllers/controllers.go +++ b/controllers/controllers.go @@ -2,12 +2,16 @@ package controllers import ( "encoding/json" + "github.com/sirupsen/logrus" "net/http" ) func writeError(w http.ResponseWriter, status int, errStr string) { w.WriteHeader(status) - json.NewEncoder(w).Encode(struct { + err := json.NewEncoder(w).Encode(struct { Error string `json:"error"` }{errStr}) + if err != nil { + logrus.Fatal("Could not write JSON response: ", err) + } }