From 979f4e27597824a8d089bd83abfcb17babb28863 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Fri, 19 Jun 2020 14:05:11 -0400 Subject: [PATCH] GET to ext/health returns 200 if heathy, else 500 --- api/health/service.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/api/health/service.go b/api/health/service.go index 51a7c82..27a15f7 100644 --- a/api/health/service.go +++ b/api/health/service.go @@ -39,8 +39,12 @@ func (h *Health) Handler() *common.HTTPHandler { newServer.RegisterCodec(codec, "application/json;charset=UTF-8") newServer.RegisterService(h, "health") handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if r.Method == http.MethodGet { // GET request --> reply with 200 - w.WriteHeader(http.StatusOK) + if r.Method == http.MethodGet { // GET request --> return 200 if getLiveness returns true, else 500 + if _, healthy := h.health.Results(); healthy { + w.WriteHeader(http.StatusOK) + } else { + w.WriteHeader(http.StatusInternalServerError) + } } else { newServer.ServeHTTP(w, r) // Other request --> use JSON RPC }