Don't exit on failure to write

OK to panic on marshal error as this would be a developer error
This commit is contained in:
Jonny Stoten
2024-06-11 11:29:09 +01:00
parent 5a1a68c732
commit f9195a2133

View File

@@ -3,7 +3,6 @@ package utils
import (
"encoding/json"
"net/http"
"os"
"github.com/open-policy-agent/frameworks/constraint/pkg/externaldata"
"k8s.io/klog/v2"
@@ -35,13 +34,13 @@ func SendResponse(results *[]externaldata.Item, systemErr string, w http.Respons
body, err := json.Marshal(response)
if err != nil {
klog.ErrorS(err, "unable to marshal response")
os.Exit(1)
panic(err)
}
w.Header().Set("Content-Type", "application/json")
_, err = w.Write(body)
if err != nil {
klog.ErrorS(err, "unable to write response")
os.Exit(1)
return
}
}