From 3ca3a7377ab909276147d74b125aee803a82c8ac Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Wed, 24 Jun 2020 12:28:16 -0400 Subject: [PATCH] return 503 rather than 500 when unhealthy --- api/health/service.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/health/service.go b/api/health/service.go index 27a15f7..b59cf7e 100644 --- a/api/health/service.go +++ b/api/health/service.go @@ -39,11 +39,11 @@ 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 --> return 200 if getLiveness returns true, else 500 + if r.Method == http.MethodGet { // GET request --> return 200 if getLiveness returns true, else 503 if _, healthy := h.health.Results(); healthy { w.WriteHeader(http.StatusOK) } else { - w.WriteHeader(http.StatusInternalServerError) + w.WriteHeader(http.StatusServiceUnavailable) } } else { newServer.ServeHTTP(w, r) // Other request --> use JSON RPC