From 2fa44f69a41308953fd089a763ab92cc95d1f108 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Fri, 10 Apr 2026 16:33:34 +0700 Subject: [PATCH] server: return 500 status on collect errors instead of 200 Errors from provider.Collect() and json.Marshal were returned with HTTP 200, making failures invisible to monitoring, proxies, and clients that check status codes. Return 500 Internal Server Error so HTTP-level tooling can detect failures without parsing the response body. --- checker/server.go | 4 ++-- checker/server_test.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/checker/server.go b/checker/server.go index 1036e99..6065fbd 100644 --- a/checker/server.go +++ b/checker/server.go @@ -114,7 +114,7 @@ func (s *Server) handleCollect(w http.ResponseWriter, r *http.Request) { data, err := s.provider.Collect(r.Context(), req.Options) if err != nil { - writeJSON(w, http.StatusOK, ExternalCollectResponse{ + writeJSON(w, http.StatusInternalServerError, ExternalCollectResponse{ Error: err.Error(), }) return @@ -122,7 +122,7 @@ func (s *Server) handleCollect(w http.ResponseWriter, r *http.Request) { raw, err := json.Marshal(data) if err != nil { - writeJSON(w, http.StatusOK, ExternalCollectResponse{ + writeJSON(w, http.StatusInternalServerError, ExternalCollectResponse{ Error: fmt.Sprintf("failed to marshal result: %v", err), }) return diff --git a/checker/server_test.go b/checker/server_test.go index 5802532..3bc36bd 100644 --- a/checker/server_test.go +++ b/checker/server_test.go @@ -143,8 +143,8 @@ func TestServer_Collect_ProviderError(t *testing.T) { } srv := newTestServer(p) rec := doRequest(srv.Handler(), "POST", "/collect", ExternalCollectRequest{Key: "test"}, nil) - if rec.Code != http.StatusOK { - t.Fatalf("POST /collect = %d, want %d", rec.Code, http.StatusOK) + if rec.Code != http.StatusInternalServerError { + t.Fatalf("POST /collect = %d, want %d", rec.Code, http.StatusInternalServerError) } var resp ExternalCollectResponse json.NewDecoder(rec.Body).Decode(&resp)