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..
pull/71/head
Quentin Machu 8 years ago committed by Jimmy Zelinskie
parent 80977f233e
commit 274a1620a5

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

Loading…
Cancel
Save