api: log instead of panic when a response could not be marshaled

In order to avoid killing Clair when there is simply a broken pipe..
This commit is contained in:
Quentin Machu 2016-02-20 15:36:32 -05:00 committed by Jimmy Zelinskie
parent 80977f233e
commit 274a1620a5

View File

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