Skip to content

Commit 64f6849

Browse files
committed
Output: send errors as {"error": ...}
1 parent 4a1b37d commit 64f6849

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

http.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,11 @@ func httpMessage(w http.ResponseWriter, code int, label string, msg string) {
137137

138138
// Output sends a JSON-encoded output.
139139
func Output(w http.ResponseWriter, output any) {
140+
if err, ok := output.(error); ok {
141+
httpError(w, err)
142+
return
143+
}
144+
140145
// if the returned type is a string, output it as a "info" message:
141146
if s, ok := output.(string); ok {
142147
httpMessage(w, http.StatusOK, "info", s)

0 commit comments

Comments
 (0)