@@ -270,10 +270,7 @@ func newGitHubClient(ctx context.Context, instanceURL string, ts oauth2.TokenSou
270270 ctx = context .WithValue (ctx , oauth2 .HTTPClient , httpClient )
271271
272272 tc := oauth2 .NewClient (ctx , ts )
273- if oauthT , ok := tc .Transport .(* oauth2.Transport ); ok {
274- oauthT .Base = & unauthorized401Logger {base : oauthT .Base }
275- }
276- wrapWithUnauthorizedRefresh (tc , ts )
273+ wrap401Handlers (tc , ts )
277274 gc := github .NewClient (tc )
278275
279276 instanceURL = strings .TrimSuffix (instanceURL , "/" )
@@ -422,10 +419,7 @@ func newGitHubGraphqlClient(ctx context.Context, instanceURL string, ts oauth2.T
422419 ctx = context .WithValue (ctx , oauth2 .HTTPClient , httpClient )
423420
424421 tc := oauth2 .NewClient (ctx , ts )
425- if oauthT , ok := tc .Transport .(* oauth2.Transport ); ok {
426- oauthT .Base = & unauthorized401Logger {base : oauthT .Base }
427- }
428- wrapWithUnauthorizedRefresh (tc , ts )
422+ wrap401Handlers (tc , ts )
429423
430424 instanceURL = strings .TrimSuffix (instanceURL , "/" )
431425 if instanceURL != "" && instanceURL != githubDotCom {
@@ -645,8 +639,13 @@ func (t *unauthorizedRefreshTransport) RoundTrip(req *http.Request) (*http.Respo
645639 return t .base .RoundTrip (retry )
646640}
647641
648- // wrapWithUnauthorizedRefresh adds the 401-retry layer if ts supports invalidation.
649- func wrapWithUnauthorizedRefresh (c * http.Client , ts oauth2.TokenSource ) {
642+ // wrap401Handlers attaches diagnostic logging beneath oauth2.Transport and the
643+ // 401-retry layer above it. The logger is installed unconditionally; the retry
644+ // only when ts supports invalidation (PAT and JWT-only sources don't).
645+ func wrap401Handlers (c * http.Client , ts oauth2.TokenSource ) {
646+ if oauthT , ok := c .Transport .(* oauth2.Transport ); ok {
647+ oauthT .Base = & unauthorized401Logger {base : oauthT .Base }
648+ }
650649 if inv , ok := ts .(tokenInvalidator ); ok {
651650 c .Transport = & unauthorizedRefreshTransport {base : c .Transport , src : inv }
652651 }
0 commit comments