@@ -75,6 +75,10 @@ export class GithubServiceImpl implements GithubService {
7575
7676 return result ;
7777 } catch ( fetchError : any ) {
78+ if ( fetchError . httpStatus ) {
79+ this . logger . warn ( `Github Service: fetch failed with HTTP ${ fetchError . httpStatus } : ${ fetchError . message } ` ) ;
80+ throw fetchError ;
81+ }
7882 this . logger . warn ( `Github Service: fetch failed: ${ fetchError . message } ${ fetchError . cause ? ` (cause: ${ fetchError . cause . message } )` : '' } ` ) ;
7983 try {
8084 this . logger . info ( 'Github Service: falling back to https module...' ) ;
@@ -92,10 +96,13 @@ export class GithubServiceImpl implements GithubService {
9296 private async fetchGithubUserWithFetch ( token : string ) : Promise < { user : GithubUser ; scopes : string [ ] } > {
9397 const response = await fetch ( 'https://api.github.com/user' , {
9498 headers : { Authorization : `Bearer ${ token } ` } ,
99+ signal : AbortSignal . timeout ( 60_000 ) ,
95100 } ) ;
96101 if ( ! response . ok ) {
97102 const message = await response . text ( ) ;
98- throw new Error ( `GitHub user request failed: ${ response . status } ${ response . statusText } - ${ message } ` ) ;
103+ const err : any = new Error ( `GitHub user request failed: ${ response . status } ${ response . statusText } - ${ message } ` ) ;
104+ err . httpStatus = response . status ;
105+ throw err ;
99106 }
100107 const user = await response . json ( ) as GithubUser ;
101108 const scopesHeader = response . headers . get ( 'x-oauth-scopes' ) ?? '' ;
@@ -138,7 +145,9 @@ export class GithubServiceImpl implements GithubService {
138145 } ) ;
139146 res . on ( 'error' , reject ) ;
140147 } ) ;
141- req . setTimeout ( 60 * 1000 ) ;
148+ req . setTimeout ( 60_000 , ( ) => {
149+ req . destroy ( new Error ( 'GitHub user request timed out after 60000ms' ) ) ;
150+ } ) ;
142151 req . on ( 'error' , reject ) ;
143152 req . end ( ) ;
144153 } ) ;
0 commit comments