diff --git a/packages/api/src/filestorage/file/services/onedrive/index.ts b/packages/api/src/filestorage/file/services/onedrive/index.ts index e306678fb..b97117466 100644 --- a/packages/api/src/filestorage/file/services/onedrive/index.ts +++ b/packages/api/src/filestorage/file/services/onedrive/index.ts @@ -12,7 +12,7 @@ import { OnedriveFileOutput } from './types'; import { OnedriveService as OnedriveFolderService } from '@filestorage/folder/services/onedrive'; @Injectable() export class OnedriveService implements IFileService { - private readonly MAX_RETRIES: number = 5; + private readonly MAX_RETRIES: number = 6; private readonly INITIAL_BACKOFF_MS: number = 1000; private readonly BATCH_SIZE: number = 20; @@ -244,6 +244,19 @@ export class OnedriveService implements IFileService { continue; } + // Handle server errors (500+) + if (error.response && error.response.status >= 500) { + const delayTime: number = backoff; + + this.logger.warn( + `Server error ${error.response.status}. Retrying in ${delayTime}ms (Attempt ${attempts}/${this.MAX_RETRIES})`, + ); + + await this.delay(delayTime); + backoff *= 2; + continue; + } + throw error; } } diff --git a/packages/api/src/filestorage/folder/services/onedrive/index.ts b/packages/api/src/filestorage/folder/services/onedrive/index.ts index 56c04e9a8..38dc78bd5 100644 --- a/packages/api/src/filestorage/folder/services/onedrive/index.ts +++ b/packages/api/src/filestorage/folder/services/onedrive/index.ts @@ -469,6 +469,19 @@ export class OnedriveService implements IFolderService { continue; } + // Handle server errors (500+) + if (error.response && error.response.status >= 500) { + const delayTime: number = backoff; + + this.logger.warn( + `Server error ${error.response.status}. Retrying in ${delayTime}ms (Attempt ${attempts}/${this.MAX_RETRIES})`, + ); + + await this.delay(delayTime); + backoff *= 2; + continue; + } + throw error; } }