Skip to content

Commit

Permalink
api: log instead of panic when a response could not be marshaled
Browse files Browse the repository at this point in the history
In order to avoid killing Clair when there is simply a broken pipe..
  • Loading branch information
Quentin-M authored and jzelinskie committed Feb 24, 2016
1 parent 80977f2 commit 274a162
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion api/v1/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,14 @@ func writeResponse(w http.ResponseWriter, r *http.Request, status int, resp inte
// Write the response.
w.WriteHeader(status)
err := json.NewEncoder(writer).Encode(resp)

if err != nil {
panic("v1: failed to marshal response: " + err.Error())
switch err.(type) {
case *json.MarshalerError, *json.UnsupportedTypeError, *json.UnsupportedValueError:
panic("v1: failed to marshal response: " + err.Error())
default:
log.Warningf("failed to write response: %s", err.Error())
}
}
}

Expand Down

0 comments on commit 274a162

Please sign in to comment.