Skip to content

Commit 04fb197

Browse files
committed
Syncs cloud integration on Authorizatin problems
(#4324)
1 parent 6dfa541 commit 04fb197

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

src/plus/integrations/models/gitHostIntegration.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -665,8 +665,7 @@ export abstract class GitHostIntegration<
665665
);
666666
return { value: pullRequests, duration: Date.now() - start };
667667
} catch (ex) {
668-
Logger.error(ex, scope);
669-
return { error: ex, duration: Date.now() - start };
668+
return this.handleProviderException(ex, scope, { error: ex, duration: Date.now() - start });
670669
}
671670
}
672671

src/plus/integrations/models/integration.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,22 @@ export abstract class IntegrationBase<
207207
void this.ensureSession({ createIfNeeded: false });
208208
}
209209

210+
private static readonly requestExceptionLimit = 5;
211+
private static readonly syncDueToRequestExceptionLimit = 1;
212+
private syncCountDueToRequestException = 0;
210213
private requestExceptionCount = 0;
211214

212215
resetRequestExceptionCount(): void {
213216
this.requestExceptionCount = 0;
217+
this.syncCountDueToRequestException = 0;
218+
}
219+
220+
/**
221+
* Resets request exceptions without resetting the amount of syncs
222+
*/
223+
smoothifyRequestExceptionCount(): void {
224+
// On resync we reset exception count only to avoid infinitive syncs on failure
225+
this.requestExceptionCount = 0;
214226
}
215227

216228
async reset(): Promise<void> {
@@ -270,7 +282,17 @@ export abstract class IntegrationBase<
270282

271283
Logger.error(ex, scope);
272284

273-
if (ex instanceof AuthenticationError || ex instanceof RequestClientError) {
285+
if (ex instanceof AuthenticationError && this._session?.cloud) {
286+
if (this.syncCountDueToRequestException < IntegrationBase.syncDueToRequestExceptionLimit) {
287+
this.syncCountDueToRequestException++;
288+
this._session = {
289+
...this._session,
290+
expiresAt: new Date(Date.now() - 1),
291+
};
292+
} else {
293+
this.trackRequestException();
294+
}
295+
} else if (ex instanceof AuthenticationError || ex instanceof RequestClientError) {
274296
this.trackRequestException();
275297
}
276298
return defaultValue;
@@ -304,7 +326,7 @@ export abstract class IntegrationBase<
304326
trackRequestException(): void {
305327
this.requestExceptionCount++;
306328

307-
if (this.requestExceptionCount >= 5 && this._session !== null) {
329+
if (this.requestExceptionCount >= IntegrationBase.requestExceptionLimit && this._session !== null) {
308330
void showIntegrationDisconnectedTooManyFailedRequestsWarningMessage(this.name);
309331
void this.disconnect({ currentSessionOnly: true });
310332
}
@@ -370,7 +392,7 @@ export abstract class IntegrationBase<
370392
}
371393

372394
this._session = session ?? null;
373-
this.resetRequestExceptionCount();
395+
this.smoothifyRequestExceptionCount();
374396

375397
if (session != null) {
376398
await this.container.storage.storeWorkspace(this.connectedKey, true);

0 commit comments

Comments
 (0)