feat: add retry on random failure

This commit is contained in:
Nevo David 2025-01-06 20:38:28 +07:00
parent 0ac7d52799
commit b2769eed2f
1 changed files with 7 additions and 1 deletions

View File

@ -23,7 +23,8 @@ export abstract class SocialAbstract {
async fetch(
url: string,
options: RequestInit = {},
identifier = ''
identifier = '',
totalRetries = 0
): Promise<Response> {
const request = await fetch(url, options);
@ -55,6 +56,11 @@ export abstract class SocialAbstract {
throw new RefreshToken(identifier, json, options.body!);
}
if (totalRetries < 2) {
await timer(2000);
return this.fetch(url, options, identifier, totalRetries + 1);
}
throw new BadBody(identifier, json, options.body!);
}