Skip to content

πŸ“¨ The ultimate agentic social media scheduling tool πŸ€–

feat: if there is a rate limit, wait two seconds and try again

Nevo Davide3bd1df158d2
diff --git a/libraries/nestjs-libraries/src/integrations/social.abstract.ts b/libraries/nestjs-libraries/src/integrations/social.abstract.ts
index b30497f69..e9fe04804 100644
--- a/libraries/nestjs-libraries/src/integrations/social.abstract.ts
+++ b/libraries/nestjs-libraries/src/integrations/social.abstract.ts
@@ -1,3 +1,5 @@
+import { timer } from '@gitroom/helpers/utils/timer';
+
export class RefreshToken {
constructor(
public identifier: string,
@@ -18,7 +20,7 @@ export class NotEnoughScopes {
}
export abstract class SocialAbstract {
- async fetch(url: string, options: RequestInit = {}, identifier = '') {
+ async fetch(url: string, options: RequestInit = {}, identifier = ''): Promise<Response> {
const request = await fetch(url, options);
if (request.status === 200 || request.status === 201) {
@@ -33,6 +35,11 @@ export abstract class SocialAbstract {
json = '{}';
}
+ if (json.includes('rate_limit_exceeded') || json.includes('Rate limit')) {
+ await timer(2000);
+ return this.fetch(url, options, identifier);
+ }
+
if (request.status === 401 || json.includes('OAuthException')) {
throw new RefreshToken(identifier, json, options.body!);
}