return 503 rather than 500 when unhealthy

This commit is contained in:
Dan Laine 2020-06-24 12:28:16 -04:00
parent 50b28ed7f3
commit 3ca3a7377a
1 changed files with 2 additions and 2 deletions

View File

@ -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