Browse Source

api: health check returns 503 if db is failing

ref #3302
Daniel Lee 8 years ago
parent
commit
4a35126bf6
1 changed files with 5 additions and 3 deletions
  1. 5 3
      pkg/api/http_server.go

+ 5 - 3
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)
 }