Skip to content

Commit f46023c

Browse files
committed
chore: error mgt for JSON problem
1 parent ab25e39 commit f46023c

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

pkg/utils/json-problem.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package utils
22

33
import (
44
"encoding/json"
5+
"fmt"
56
"net/http"
67
)
78

@@ -24,5 +25,7 @@ func WriteJSONProblem(w http.ResponseWriter, problem JSONProblem) {
2425
w.Header().Set("Content-Type", "application/problem+json; charset=utf-8")
2526
w.Header().Set("X-Content-Type-Options", "nosniff")
2627
w.WriteHeader(problem.Status)
27-
json.NewEncoder(w).Encode(problem)
28+
if err := json.NewEncoder(w).Encode(problem); err != nil {
29+
fmt.Fprintf(w, `{"title": "%d", "detail": "%s"}`, http.StatusInternalServerError, err.Error())
30+
}
2831
}

0 commit comments

Comments
 (0)