@@ -269,10 +269,22 @@ export abstract class IntegrationBase<
269
269
void this . ensureSession ( { createIfNeeded : false } ) ;
270
270
}
271
271
272
+ private static readonly requestExceptionLimit = 5 ;
273
+ private static readonly syncDueToRequestExceptionLimit = 1 ;
274
+ private syncCountDueToRequestException = 0 ;
272
275
private requestExceptionCount = 0 ;
273
276
274
277
resetRequestExceptionCount ( ) : void {
275
278
this . requestExceptionCount = 0 ;
279
+ this . syncCountDueToRequestException = 0 ;
280
+ }
281
+
282
+ /**
283
+ * Resets request exceptions without resetting the amount of syncs
284
+ */
285
+ smoothifyRequestExceptionCount ( ) : void {
286
+ // On resync we reset exception count only to avoid infinitive syncs on failure
287
+ this . requestExceptionCount = 0 ;
276
288
}
277
289
278
290
async reset ( ) : Promise < void > {
@@ -321,7 +333,17 @@ export abstract class IntegrationBase<
321
333
322
334
Logger . error ( ex , scope ) ;
323
335
324
- if ( ex instanceof AuthenticationError || ex instanceof RequestClientError ) {
336
+ if ( ex instanceof AuthenticationError && this . _session ?. cloud ) {
337
+ if ( this . syncCountDueToRequestException < IntegrationBase . syncDueToRequestExceptionLimit ) {
338
+ this . syncCountDueToRequestException ++ ;
339
+ this . _session = {
340
+ ...this . _session ,
341
+ expiresAt : new Date ( Date . now ( ) - 1 ) ,
342
+ } ;
343
+ } else {
344
+ this . trackRequestException ( ) ;
345
+ }
346
+ } else if ( ex instanceof AuthenticationError || ex instanceof RequestClientError ) {
325
347
this . trackRequestException ( ) ;
326
348
}
327
349
return defaultValue ;
@@ -343,7 +365,7 @@ export abstract class IntegrationBase<
343
365
trackRequestException ( ) : void {
344
366
this . requestExceptionCount ++ ;
345
367
346
- if ( this . requestExceptionCount >= 5 && this . _session !== null ) {
368
+ if ( this . requestExceptionCount >= IntegrationBase . requestExceptionLimit && this . _session !== null ) {
347
369
void showIntegrationDisconnectedTooManyFailedRequestsWarningMessage ( this . name ) ;
348
370
void this . disconnect ( { currentSessionOnly : true } ) ;
349
371
}
@@ -409,7 +431,7 @@ export abstract class IntegrationBase<
409
431
}
410
432
411
433
this . _session = session ?? null ;
412
- this . resetRequestExceptionCount ( ) ;
434
+ this . smoothifyRequestExceptionCount ( ) ;
413
435
414
436
if ( session != null ) {
415
437
await this . container . storage . storeWorkspace ( this . connectedKey , true ) ;
@@ -1385,8 +1407,7 @@ export abstract class HostingIntegration<
1385
1407
) ;
1386
1408
return { value : pullRequests , duration : Date . now ( ) - start } ;
1387
1409
} catch ( ex ) {
1388
- Logger . error ( ex , scope ) ;
1389
- return { error : ex , duration : Date . now ( ) - start } ;
1410
+ return this . handleProviderException ( ex , scope , { error : ex , duration : Date . now ( ) - start } ) ;
1390
1411
}
1391
1412
}
1392
1413
0 commit comments