Skip to content

Commit 67283f3

Browse files
committed
fix(connector): classify GraphQL responses on the App-token path
newGitHubAppClients shared one unwrapped HTTP client for REST and GraphQL, so the GraphQL client lost the statusClassifyingTransport that newGitHubGraphqlClient applies. Without it, shurcooL/githubv4 surfaces 429/5xx as opaque strings that reach the SDK as codes.Unknown and abort the sync instead of being retried. Wrap the GraphQL client's transport with statusClassifyingTransport, layered above tokenRefreshTransport so a 401 is still observed and retried before any surviving non-2xx is converted to a classified error. REST is unchanged (go-github classifies via wrapGitHubError).
1 parent e5383ef commit 67283f3

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

pkg/connector/token_refresh.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,15 @@ func newGitHubAppHTTPClient(ctx context.Context, rts *refreshableTokenSource) (*
132132
// newGitHubAppClients constructs the REST and GraphQL clients used by the
133133
// GitHub App install-token path, sharing the layered httpClient so the
134134
// 401-refresh middleware applies to both surfaces.
135+
//
136+
// The GraphQL client gets an extra statusClassifyingTransport layered on top of
137+
// the shared transport: shurcooL/githubv4 surfaces non-2xx responses as opaque
138+
// strings, so without it transient errors (429, 5xx) would reach the SDK as
139+
// codes.Unknown and abort the sync instead of being retried. It must sit above
140+
// the 401-retry layer so tokenRefreshTransport still observes a raw 401 and can
141+
// retry it; only a non-2xx that survives the retry is converted to a classified
142+
// error. The REST client doesn't need this — go-github exposes structured
143+
// errors that wrapGitHubError classifies at the call site.
135144
func newGitHubAppClients(instanceURL string, httpClient *http.Client) (*github.Client, *githubv4.Client, error) {
136145
instanceURL = strings.TrimSuffix(instanceURL, "/")
137146

@@ -144,16 +153,21 @@ func newGitHubAppClients(instanceURL string, httpClient *http.Client) (*github.C
144153
}
145154
}
146155

156+
gqlHTTPClient := &http.Client{
157+
Timeout: httpClient.Timeout,
158+
Transport: &statusClassifyingTransport{base: httpClient.Transport},
159+
}
160+
147161
var gqlClient *githubv4.Client
148162
if instanceURL != "" && instanceURL != githubDotCom {
149163
gqlURL, err := url.Parse(instanceURL)
150164
if err != nil {
151165
return nil, nil, err
152166
}
153167
gqlURL.Path = "/api/graphql"
154-
gqlClient = githubv4.NewEnterpriseClient(gqlURL.String(), httpClient)
168+
gqlClient = githubv4.NewEnterpriseClient(gqlURL.String(), gqlHTTPClient)
155169
} else {
156-
gqlClient = githubv4.NewClient(httpClient)
170+
gqlClient = githubv4.NewClient(gqlHTTPClient)
157171
}
158172
return gc, gqlClient, nil
159173
}

0 commit comments

Comments
 (0)