Skip to content

Commit 86c1700

Browse files
chore: Apply coderabbitai suggestions to improve logic in che-api/github-service
Signed-off-by: Roman Nikitenko <rnikiten@redhat.com> Assisted-by: Cursor AI
1 parent 33e25dd commit 86c1700

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

code/extensions/che-api/src/impl/github-service-impl.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)