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:
parent
80977f233e
commit
274a1620a5
@ -84,8 +84,14 @@ func writeResponse(w http.ResponseWriter, r *http.Request, status int, resp inte
|
|||||||
// Write the response.
|
// Write the response.
|
||||||
w.WriteHeader(status)
|
w.WriteHeader(status)
|
||||||
err := json.NewEncoder(writer).Encode(resp)
|
err := json.NewEncoder(writer).Encode(resp)
|
||||||
|
|
||||||
if err != nil {
|
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…
Reference in New Issue
Block a user