@@ -269,10 +269,22 @@ export abstract class IntegrationBase<
269269 void this . ensureSession ( { createIfNeeded : false } ) ;
270270 }
271271
272+ private static readonly requestExceptionLimit = 5 ;
273+ private static readonly syncDueToRequestExceptionLimit = 1 ;
274+ private syncCountDueToRequestException = 0 ;
272275 private requestExceptionCount = 0 ;
273276
274277 resetRequestExceptionCount ( ) : void {
275278 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 ;
276288 }
277289
278290 async reset ( ) : Promise < void > {
@@ -332,7 +344,17 @@ export abstract class IntegrationBase<
332344
333345 Logger . error ( ex , scope ) ;
334346
335- if ( ex instanceof AuthenticationError || ex instanceof RequestClientError ) {
347+ if ( ex instanceof AuthenticationError && this . _session ?. cloud ) {
348+ if ( this . syncCountDueToRequestException < IntegrationBase . syncDueToRequestExceptionLimit ) {
349+ this . syncCountDueToRequestException ++ ;
350+ this . _session = {
351+ ...this . _session ,
352+ expiresAt : new Date ( Date . now ( ) - 1 ) ,
353+ } ;
354+ } else {
355+ this . trackRequestException ( ) ;
356+ }
357+ } else if ( ex instanceof AuthenticationError || ex instanceof RequestClientError ) {
336358 this . trackRequestException ( ) ;
337359 }
338360 return defaultValue ;
@@ -366,7 +388,7 @@ export abstract class IntegrationBase<
366388 trackRequestException ( ) : void {
367389 this . requestExceptionCount ++ ;
368390
369- if ( this . requestExceptionCount >= 5 && this . _session !== null ) {
391+ if ( this . requestExceptionCount >= IntegrationBase . requestExceptionLimit && this . _session !== null ) {
370392 void showIntegrationDisconnectedTooManyFailedRequestsWarningMessage ( this . name ) ;
371393 void this . disconnect ( { currentSessionOnly : true } ) ;
372394 }
@@ -432,7 +454,7 @@ export abstract class IntegrationBase<
432454 }
433455
434456 this . _session = session ?? null ;
435- this . resetRequestExceptionCount ( ) ;
457+ this . smoothifyRequestExceptionCount ( ) ;
436458
437459 if ( session != null ) {
438460 await this . container . storage . storeWorkspace ( this . connectedKey , true ) ;
@@ -1408,8 +1430,7 @@ export abstract class HostingIntegration<
14081430 ) ;
14091431 return { value : pullRequests , duration : Date . now ( ) - start } ;
14101432 } catch ( ex ) {
1411- Logger . error ( ex , scope ) ;
1412- return { error : ex , duration : Date . now ( ) - start } ;
1433+ return this . handleProviderException ( ex , scope , { error : ex , duration : Date . now ( ) - start } ) ;
14131434 }
14141435 }
14151436
0 commit comments