Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions internal/integrations/repos.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
24 changes: 24 additions & 0 deletions internal/integrations/repos_err_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}