Skip to content

Commit b2769ee

Browse files
committed
feat: add retry on random failure
1 parent 0ac7d52 commit b2769ee

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

libraries/nestjs-libraries/src/integrations/social.abstract.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ export abstract class SocialAbstract {
2323
async fetch(
2424
url: string,
2525
options: RequestInit = {},
26-
identifier = ''
26+
identifier = '',
27+
totalRetries = 0
2728
): Promise<Response> {
2829
const request = await fetch(url, options);
2930

@@ -55,6 +56,11 @@ export abstract class SocialAbstract {
5556
throw new RefreshToken(identifier, json, options.body!);
5657
}
5758

59+
if (totalRetries < 2) {
60+
await timer(2000);
61+
return this.fetch(url, options, identifier, totalRetries + 1);
62+
}
63+
5864
throw new BadBody(identifier, json, options.body!);
5965
}
6066

0 commit comments

Comments
 (0)