Skip to content

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

feat: retry

Nevo David7b8fa7fb7bf2
diff --git a/libraries/nestjs-libraries/src/integrations/social.abstract.ts b/libraries/nestjs-libraries/src/integrations/social.abstract.ts
index b0ef56703..778864fb2 100644
--- a/libraries/nestjs-libraries/src/integrations/social.abstract.ts
+++ b/libraries/nestjs-libraries/src/integrations/social.abstract.ts
@@ -29,7 +29,9 @@ export abstract class SocialAbstract {
public handleErrors(
body: string
- ): { type: 'refresh-token' | 'bad-body'; value: string } | undefined {
+ ):
+ | { type: 'refresh-token' | 'bad-body' | 'retry'; value: string }
+ | undefined {
return undefined;
}
@@ -112,6 +114,11 @@ export abstract class SocialAbstract {
const handleError = this.handleErrors(json || '{}');
+ if (handleError?.type === 'retry') {
+ await timer(5000);
+ return this.fetch(url, options, identifier, totalRetries + 1);
+ }
+
if (
request.status === 401 &&
(handleError?.type === 'refresh-token' || !handleError)
diff --git a/libraries/nestjs-libraries/src/integrations/social/instagram.provider.ts b/libraries/nestjs-libraries/src/integrations/social/instagram.provider.ts
index 2bdf28894..0b7ada53b 100644
--- a/libraries/nestjs-libraries/src/integrations/social/instagram.provider.ts
+++ b/libraries/nestjs-libraries/src/integrations/social/instagram.provider.ts
@@ -46,11 +46,18 @@ export class InstagramProvider
public override handleErrors(body: string):
| {
- type: 'refresh-token' | 'bad-body';
+ type: 'refresh-token' | 'bad-body' | 'retry';
value: string;
}
| undefined {
+ if (body.indexOf('An unknown error occurred') > -1) {
+ return {
+ type: 'retry' as const,
+ value: 'An unknown error occurred, please try again later',
+ };
+ }
+
if (body.indexOf('REVOKED_ACCESS_TOKEN') > -1) {
return {
type: 'refresh-token' as const,
diff --git a/libraries/nestjs-libraries/src/integrations/social/instagram.standalone.provider.ts b/libraries/nestjs-libraries/src/integrations/social/instagram.standalone.provider.ts
index 68938b174..523bcda2f 100644
--- a/libraries/nestjs-libraries/src/integrations/social/instagram.standalone.provider.ts
+++ b/libraries/nestjs-libraries/src/integrations/social/instagram.standalone.provider.ts
@@ -30,7 +30,7 @@ export class InstagramStandaloneProvider
editor = 'normal' as const;
- public override handleErrors(body: string): { type: "refresh-token" | "bad-body"; value: string } | undefined {
+ public override handleErrors(body: string): { type: "refresh-token" | "bad-body" | "retry"; value: string } | undefined {
return instagramProvider.handleErrors(body);
}