Skip to content

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

feat: instagram refresh fix

Nevo David186d3370e97a
diff --git a/libraries/nestjs-libraries/src/integrations/social.abstract.ts b/libraries/nestjs-libraries/src/integrations/social.abstract.ts
index ec13f7f65..c52cf107d 100644
--- a/libraries/nestjs-libraries/src/integrations/social.abstract.ts
+++ b/libraries/nestjs-libraries/src/integrations/social.abstract.ts
@@ -51,7 +51,8 @@ export abstract class SocialAbstract {
maxConcurrentJob = 1;
public handleErrors(
- body: string
+ body: string,
+ status: number,
):
| { type: 'refresh-token' | 'bad-body' | 'retry'; value: string }
| undefined {
@@ -78,7 +79,7 @@ export abstract class SocialAbstract {
try {
value = await func();
} catch (err) {
- const handle = this.handleErrors(safeStringify(err));
+ const handle = this.handleErrors(safeStringify(err), 200);
value = { err: true, value: 'Unknown Error', ...(handle || {}) };
}
@@ -121,7 +122,7 @@ export abstract class SocialAbstract {
json = '{}';
}
- const handleError = this.handleErrors(json || '{}');
+ const handleError = this.handleErrors(json || '{}', request.status);
if (
request.status === 429 ||
diff --git a/libraries/nestjs-libraries/src/integrations/social/facebook.provider.ts b/libraries/nestjs-libraries/src/integrations/social/facebook.provider.ts
index 052ef46a8..98e41519b 100644
--- a/libraries/nestjs-libraries/src/integrations/social/facebook.provider.ts
+++ b/libraries/nestjs-libraries/src/integrations/social/facebook.provider.ts
@@ -31,7 +31,10 @@ export class FacebookProvider extends SocialAbstract implements SocialProvider {
}
dto = FacebookDto;
- override handleErrors(body: string):
+ override handleErrors(
+ body: string,
+ status: number
+ ):
| {
type: 'refresh-token' | 'bad-body';
value: string;
@@ -129,7 +132,8 @@ export class FacebookProvider extends SocialAbstract implements SocialProvider {
if (body.indexOf('1404112') > -1) {
return {
type: 'bad-body' as const,
- value: 'For security reasons, your account has limited access to the site for a few days',
+ value:
+ 'For security reasons, your account has limited access to the site for a few days',
};
}
@@ -155,6 +159,14 @@ export class FacebookProvider extends SocialAbstract implements SocialProvider {
};
}
+ if (status === 401) {
+ return {
+ type: 'bad-body' as const,
+ value:
+ 'An unknown error occurred, please try again later or contact support',
+ };
+ }
+
return undefined;
}
@@ -289,8 +301,9 @@ export class FacebookProvider extends SocialAbstract implements SocialProvider {
// Also fetch pages via Business Manager API to discover pages
// not selected during the OAuth page selection step
try {
- let bizUrl: string | undefined =
- `https://graph.facebook.com/v20.0/me/businesses?access_token=${accessToken}`;
+ let bizUrl:
+ | string
+ | undefined = `https://graph.facebook.com/v20.0/me/businesses?access_token=${accessToken}`;
while (bizUrl) {
const bizResponse = await (await fetch(bizUrl)).json();
@@ -357,8 +370,9 @@ export class FacebookProvider extends SocialAbstract implements SocialProvider {
// 2. Check Business Manager owned_pages and client_pages
try {
- let bizUrl: string | undefined =
- `https://graph.facebook.com/v20.0/me/businesses?access_token=${accessToken}`;
+ let bizUrl:
+ | string
+ | undefined = `https://graph.facebook.com/v20.0/me/businesses?access_token=${accessToken}`;
while (bizUrl) {
const bizResponse = await (await fetch(bizUrl)).json();
diff --git a/libraries/nestjs-libraries/src/integrations/social/instagram.provider.ts b/libraries/nestjs-libraries/src/integrations/social/instagram.provider.ts
index 435d23e94..6fc04acb0 100644
--- a/libraries/nestjs-libraries/src/integrations/social/instagram.provider.ts
+++ b/libraries/nestjs-libraries/src/integrations/social/instagram.provider.ts
@@ -52,7 +52,10 @@ export class InstagramProvider
};
}
- public override handleErrors(body: string):
+ public override handleErrors(
+ body: string,
+ status: number
+ ):
| {
type: 'refresh-token' | 'bad-body' | 'retry';
value: string;
@@ -272,7 +275,8 @@ export class InstagramProvider
if (body.indexOf('190,') > -1) {
return {
type: 'bad-body' as const,
- value: 'The account is missing some permissions to perform this action, please re-add the account and allow all permissions',
+ value:
+ 'The account is missing some permissions to perform this action, please re-add the account and allow all permissions',
};
}
@@ -308,7 +312,15 @@ export class InstagramProvider
if (body.indexOf('param collaborators is not allowed') > -1) {
return {
type: 'bad-body' as const,
- value: 'Collaborators are not allowed for carousel'
+ value: 'Collaborators are not allowed for carousel',
+ };
+ }
+
+ if (status === 401) {
+ return {
+ type: 'bad-body' as const,
+ value:
+ 'An unknown error occurred, please try again later or contact support',
};
}
@@ -439,8 +451,9 @@ export class InstagramProvider
// Also fetch pages via Business Manager API to discover pages
// not selected during the OAuth page selection step
try {
- let bizUrl: string | undefined =
- `https://graph.facebook.com/v20.0/me/businesses?access_token=${accessToken}`;
+ let bizUrl:
+ | string
+ | undefined = `https://graph.facebook.com/v20.0/me/businesses?access_token=${accessToken}`;
while (bizUrl) {
const bizResponse = await (await fetch(bizUrl)).json();
@@ -536,7 +549,9 @@ export class InstagramProvider
? `&caption=${encodeURIComponent(firstPost.message)}`
: ``;
const isCarousel =
- (firstPost?.media?.length || 0) > 1 && !isStory ? `&is_carousel_item=true` : ``;
+ (firstPost?.media?.length || 0) > 1 && !isStory
+ ? `&is_carousel_item=true`
+ : ``;
const mediaType =
m.path.indexOf('.mp4') > -1
? firstPost?.media?.length === 1
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 5681d09e8..6051e4034 100644
--- a/libraries/nestjs-libraries/src/integrations/social/instagram.standalone.provider.ts
+++ b/libraries/nestjs-libraries/src/integrations/social/instagram.standalone.provider.ts
@@ -40,11 +40,12 @@ export class InstagramStandaloneProvider
}
public override handleErrors(
- body: string
+ body: string,
+ status: number
):
| { type: 'refresh-token' | 'bad-body' | 'retry'; value: string }
| undefined {
- return instagramProvider.handleErrors(body);
+ return instagramProvider.handleErrors(body, status);
}
async refreshToken(refresh_token: string): Promise<AuthTokenDetails> {