From e103f5a2ea4c2367ec3219d79df46ee2bd1054a7 Mon Sep 17 00:00:00 2001 From: Keloran Date: Wed, 2 Dec 2026 15:53:33 +0000 Subject: [PATCH] slight change --- internal/integrations/repos.go | 3 +++ internal/integrations/repos_err_test.go | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 internal/integrations/repos_err_test.go diff --git a/internal/integrations/repos.go b/internal/integrations/repos.go index 504de6c..8a79405 100644 --- a/internal/integrations/repos.go +++ b/internal/integrations/repos.go @@ -68,6 +68,9 @@ func (h System) providerParam(w http.ResponseWriter, r *http.Request) (string, b } func gitErr(w http.ResponseWriter, r *http.Request, err error) { + if httpx.Canceled(err) { + return // the client left: nobody to answer, nothing to report (TL-892) + } switch { case errors.Is(err, ErrProviderOff), errors.Is(err, secrets.ErrNoKey): httpx.Error(w, r, http.StatusServiceUnavailable, httpx.Code("integration_not_configured", "this integration isn't configured on the server")) diff --git a/internal/integrations/repos_err_test.go b/internal/integrations/repos_err_test.go new file mode 100644 index 0000000..6d1235d --- /dev/null +++ b/internal/integrations/repos_err_test.go @@ -0,0 +1,24 @@ +package integrations + +import ( + "context" + "fmt" + "net/http" + "net/http/httptest" + "testing" +) + +// TL-892: a request the client gave up on isn't an error to answer or report. +func TestGitErrCanceled(t *testing.T) { + w := httptest.NewRecorder() + gitErr(w, httptest.NewRequest(http.MethodGet, "/", nil), fmt.Errorf("list repos: %w", context.Canceled)) + if w.Body.Len() != 0 { + t.Fatalf("canceled request answered: %d %q", w.Code, w.Body.String()) + } + + w = httptest.NewRecorder() + gitErr(w, httptest.NewRequest(http.MethodGet, "/", nil), fmt.Errorf("boom")) + if w.Code != http.StatusInternalServerError { + t.Fatalf("unknown error: got %d, want 500", w.Code) + } +}