From 505a3d3972311c23484324575577851d43a57cf2 Mon Sep 17 00:00:00 2001 From: yusing Date: Wed, 17 Dec 2025 12:24:04 +0800 Subject: [PATCH] refactor(http): enhance health check error logic by treating all 5xx as unhealthy --- internal/watcher/health/monitor/http.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/internal/watcher/health/monitor/http.go b/internal/watcher/health/monitor/http.go index b74cc879..58c596b9 100644 --- a/internal/watcher/health/monitor/http.go +++ b/internal/watcher/health/monitor/http.go @@ -60,8 +60,7 @@ func (mon *HTTPHealthMonitor) CheckHealth() (types.HealthCheckResult, error) { respErr := pinger.DoTimeout(req, resp, mon.config.Timeout) lat := time.Since(start) - switch { - case respErr != nil: + if respErr != nil { // treat TLS error as healthy var tlsErr *tls.CertificateVerificationError if ok := errors.As(respErr, &tlsErr); !ok { @@ -70,7 +69,9 @@ func (mon *HTTPHealthMonitor) CheckHealth() (types.HealthCheckResult, error) { Detail: respErr.Error(), }, nil } - case resp.StatusCode() == fasthttp.StatusServiceUnavailable: + } + + if status := resp.StatusCode(); status >= 500 && status < 600 { return types.HealthCheckResult{ Latency: lat, Detail: fasthttp.StatusMessage(resp.StatusCode()),