From 274a1620a50815149671368f1a1feda409830286 Mon Sep 17 00:00:00 2001 From: Quentin Machu Date: Sat, 20 Feb 2016 15:36:32 -0500 Subject: [PATCH] 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.. --- api/v1/routes.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/api/v1/routes.go b/api/v1/routes.go index 60577d1e..fab222c4 100644 --- a/api/v1/routes.go +++ b/api/v1/routes.go @@ -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()) + } } }