From b684b77a0c99e27ee9113ad7c2f962c11c62341a Mon Sep 17 00:00:00 2001 From: Matt Robenolt Date: Tue, 2 Jun 2015 23:27:47 -0700 Subject: [PATCH] Return valid json from StatusHandler Signed-off-by: Matt Robenolt --- health/health.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/health/health.go b/health/health.go index 512539c1..8a4df776 100644 --- a/health/health.go +++ b/health/health.go @@ -195,11 +195,16 @@ func StatusHandler(w http.ResponseWriter, r *http.Request) { if len(checksStatus) != 0 { w.WriteHeader(http.StatusServiceUnavailable) } - err := json.NewEncoder(w).Encode(checksStatus) + encoder := json.NewEncoder(w) + err := encoder.Encode(checksStatus) // Parsing of the JSON failed. Returning generic error message if err != nil { - w.Write([]byte("{server_error: 'Could not parse error message'}")) + encoder.Encode(struct { + ServerError string `json:"server_error"` + }{ + ServerError: "Could not parse error message", + }) } } else { w.WriteHeader(http.StatusNotFound)