Skip to content
This repository was archived by the owner on Nov 14, 2025. It is now read-only.

Commit a41d53b

Browse files
authored
Improve error handling and retry logic for authentication token retrieval; refactor end game check in CodeReviewChat (#334)
1 parent 63dd4fb commit a41d53b

File tree

4 files changed

+62
-12
lines changed

4 files changed

+62
-12
lines changed

code-review-chat/CodeReviewChat.js

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

code-review-chat/CodeReviewChat.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export function createPRObject(pullRequestFromApi: any): PR {
8181
}
8282

8383
class Chatter {
84-
constructor(protected slackToken: string, protected notificationChannelID: string) { }
84+
constructor(protected slackToken: string, protected notificationChannelID: string) {}
8585

8686
async getChat(): Promise<{ client: WebClient; channel: string }> {
8787
const web = new WebClient(this.slackToken);
@@ -282,7 +282,13 @@ export class CodeReviewChat extends Chatter {
282282
return;
283283
}
284284

285-
const isEndGame = (await isInsiderFrozen()) ?? false;
285+
let isEndGame = false;
286+
try {
287+
isEndGame = (await isInsiderFrozen()) ?? false;
288+
} catch (error) {
289+
safeLog(`Error determining if insider is frozen: ${(error as Error).message}`);
290+
}
291+
286292
// This is an external PR which already received one review and is just awaiting a second
287293
const data = await this.issue.getIssue();
288294
if (this._externalContributorPR) {

common/Action.js

Lines changed: 23 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

common/Action.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,29 @@ export async function getAuthenticationToken(): Promise<string> {
253253
const installationId = getInput('app_installation_id');
254254
const privateKey = getInput('app_private_key');
255255
if (appId && installationId && privateKey) {
256-
const appAuth = createAppAuth({ appId, installationId, privateKey });
257-
return (await appAuth({ type: 'installation' })).token;
258-
} else {
259-
throw Error('Input required: app_id, app_installation_id, app_private_key');
256+
const maxAttempts = 3;
257+
let attempts = 0;
258+
259+
while (attempts < maxAttempts) {
260+
try {
261+
const appAuth = createAppAuth({ appId, installationId, privateKey });
262+
return (await appAuth({ type: 'installation' })).token;
263+
} catch (error: any) {
264+
if (error.response && error.response.status === 504) {
265+
attempts++;
266+
const delay = Math.pow(2, attempts) * 1000; // Exponential backoff
267+
safeLog(
268+
`Attempt ${attempts} failed with 504 error. Retrying in ${delay / 1000} seconds.`,
269+
);
270+
if (attempts >= maxAttempts) {
271+
throw new Error('Max retry attempts reached. Please try again later');
272+
}
273+
await new Promise((resolve) => setTimeout(resolve, delay));
274+
} else {
275+
throw error;
276+
}
277+
}
278+
}
260279
}
280+
throw Error('Failed to get authentication token');
261281
}

0 commit comments

Comments
 (0)