Skip to content

Commit e3bd1df

Browse files
committed
feat: if there is a rate limit, wait two seconds and try again
1 parent e4ac191 commit e3bd1df

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { timer } from '@gitroom/helpers/utils/timer';
2+
13
export class RefreshToken {
24
constructor(
35
public identifier: string,
@@ -18,7 +20,7 @@ export class NotEnoughScopes {
1820
}
1921

2022
export abstract class SocialAbstract {
21-
async fetch(url: string, options: RequestInit = {}, identifier = '') {
23+
async fetch(url: string, options: RequestInit = {}, identifier = ''): Promise<Response> {
2224
const request = await fetch(url, options);
2325

2426
if (request.status === 200 || request.status === 201) {
@@ -33,6 +35,11 @@ export abstract class SocialAbstract {
3335
json = '{}';
3436
}
3537

38+
if (json.includes('rate_limit_exceeded') || json.includes('Rate limit')) {
39+
await timer(2000);
40+
return this.fetch(url, options, identifier);
41+
}
42+
3643
if (request.status === 401 || json.includes('OAuthException')) {
3744
throw new RefreshToken(identifier, json, options.body!);
3845
}

0 commit comments

Comments
 (0)