From 4a35126bf61cf7603159b221937981ddfe3d3aa6 Mon Sep 17 00:00:00 2001 From: Daniel Lee Date: Wed, 10 May 2017 15:23:59 +0200 Subject: [PATCH] api: health check returns 503 if db is failing ref #3302 --- pkg/api/http_server.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pkg/api/http_server.go b/pkg/api/http_server.go index 06ef5a22125..1e143ef876f 100644 --- a/pkg/api/http_server.go +++ b/pkg/api/http_server.go @@ -189,11 +189,13 @@ func (hs *HttpServer) healthHandler(ctx *macaron.Context) { if err := bus.Dispatch(&models.GetDBHealthQuery{}); err != nil { data.Set("database", "failing") + ctx.Resp.Header().Set("Content-Type", "application/json; charset=UTF-8") + ctx.Resp.WriteHeader(503) + } else { + ctx.Resp.Header().Set("Content-Type", "application/json; charset=UTF-8") + ctx.Resp.WriteHeader(200) } - ctx.Resp.Header().Set("Content-Type", "application/json; charset=UTF-8") - ctx.Resp.WriteHeader(200) - dataBytes, _ := data.EncodePretty() ctx.Resp.Write(dataBytes) }