Skip to content

Commit

Permalink
fix: onedrive: add error handling for 500 status errors
Browse files Browse the repository at this point in the history
  • Loading branch information
amuwal committed Dec 19, 2024
1 parent aa2abb0 commit c0d9375
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
15 changes: 14 additions & 1 deletion packages/api/src/filestorage/file/services/onedrive/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
}
Expand Down
13 changes: 13 additions & 0 deletions packages/api/src/filestorage/folder/services/onedrive/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down

0 comments on commit c0d9375

Please sign in to comment.