From f46023ceb4b06d84dd3580bd8ec8d89182a7473b Mon Sep 17 00:00:00 2001 From: Nicolas Carlier Date: Sun, 4 Aug 2024 05:58:48 +0000 Subject: [PATCH] chore: error mgt for JSON problem --- pkg/utils/json-problem.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/utils/json-problem.go b/pkg/utils/json-problem.go index a131f1ab..bcc5dd54 100644 --- a/pkg/utils/json-problem.go +++ b/pkg/utils/json-problem.go @@ -2,6 +2,7 @@ package utils import ( "encoding/json" + "fmt" "net/http" ) @@ -24,5 +25,7 @@ func WriteJSONProblem(w http.ResponseWriter, problem JSONProblem) { w.Header().Set("Content-Type", "application/problem+json; charset=utf-8") w.Header().Set("X-Content-Type-Options", "nosniff") w.WriteHeader(problem.Status) - json.NewEncoder(w).Encode(problem) + if err := json.NewEncoder(w).Encode(problem); err != nil { + fmt.Fprintf(w, `{"title": "%d", "detail": "%s"}`, http.StatusInternalServerError, err.Error()) + } }