@@ -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 > {
@@ -332,7 +344,17 @@ export abstract class IntegrationBase<
332
344
333
345
Logger . error ( ex , scope ) ;
334
346
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 ) {
336
358
this . trackRequestException ( ) ;
337
359
}
338
360
return defaultValue ;
@@ -366,7 +388,7 @@ export abstract class IntegrationBase<
366
388
trackRequestException ( ) : void {
367
389
this . requestExceptionCount ++ ;
368
390
369
- if ( this . requestExceptionCount >= 5 && this . _session !== null ) {
391
+ if ( this . requestExceptionCount >= IntegrationBase . requestExceptionLimit && this . _session !== null ) {
370
392
void showIntegrationDisconnectedTooManyFailedRequestsWarningMessage ( this . name ) ;
371
393
void this . disconnect ( { currentSessionOnly : true } ) ;
372
394
}
@@ -432,7 +454,7 @@ export abstract class IntegrationBase<
432
454
}
433
455
434
456
this . _session = session ?? null ;
435
- this . resetRequestExceptionCount ( ) ;
457
+ this . smoothifyRequestExceptionCount ( ) ;
436
458
437
459
if ( session != null ) {
438
460
await this . container . storage . storeWorkspace ( this . connectedKey , true ) ;
@@ -1408,8 +1430,7 @@ export abstract class HostingIntegration<
1408
1430
) ;
1409
1431
return { value : pullRequests , duration : Date . now ( ) - start } ;
1410
1432
} 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 } ) ;
1413
1434
}
1414
1435
}
1415
1436
0 commit comments