Skip to content

Commit

Permalink
chore: error mgt for JSON problem
Browse files Browse the repository at this point in the history
  • Loading branch information
ncarlier committed Aug 4, 2024
1 parent ab25e39 commit f46023c
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pkg/utils/json-problem.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package utils

import (
"encoding/json"
"fmt"
"net/http"
)

Expand All @@ -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())
}
}

0 comments on commit f46023c

Please sign in to comment.