Skip to content

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

feat: better errors

Nevo David44688ee77a56
diff --git a/libraries/nestjs-libraries/src/database/prisma/posts/posts.service.ts b/libraries/nestjs-libraries/src/database/prisma/posts/posts.service.ts
index fbd051f22..70308a970 100644
--- a/libraries/nestjs-libraries/src/database/prisma/posts/posts.service.ts
+++ b/libraries/nestjs-libraries/src/database/prisma/posts/posts.service.ts
@@ -162,7 +162,24 @@ export class PostsService {
true
);
- console.error('[Error] posting on', firstPost.integration?.providerIdentifier, err);
+ if (err instanceof BadBody) {
+ console.error(
+ '[Error] posting on',
+ firstPost.integration?.providerIdentifier,
+ err.identifier,
+ err.json,
+ err.body,
+ err
+ );
+
+ return ;
+ }
+
+ console.error(
+ '[Error] posting on',
+ firstPost.integration?.providerIdentifier,
+ err
+ );
}
}
diff --git a/libraries/nestjs-libraries/src/integrations/social.abstract.ts b/libraries/nestjs-libraries/src/integrations/social.abstract.ts
index eee510db9..9d06d017e 100644
--- a/libraries/nestjs-libraries/src/integrations/social.abstract.ts
+++ b/libraries/nestjs-libraries/src/integrations/social.abstract.ts
@@ -1,14 +1,22 @@
export class RefreshToken {
- constructor(public json: string, public body: BodyInit) {}
+ constructor(
+ public identifier: string,
+ public json: string,
+ public body: BodyInit
+ ) {}
}
export class BadBody {
- constructor(public json: string, public body: BodyInit) {}
+ constructor(
+ public identifier: string,
+ public json: string,
+ public body: BodyInit
+ ) {}
}
export class NotEnoughScopes {}
export abstract class SocialAbstract {
- async fetch(url: string, options: RequestInit = {}) {
+ async fetch(url: string, options: RequestInit = {}, identifier = '') {
const request = await fetch(url, options);
if (request.status === 200 || request.status === 201) {
@@ -17,20 +25,16 @@ export abstract class SocialAbstract {
let json = '{}';
try {
- json = await request.json();
+ json = await request.text();
} catch (err) {
json = '{}';
}
if (request.status === 401) {
- throw new RefreshToken(json, options.body!);
+ throw new RefreshToken(identifier, json, options.body!);
}
- if (request.status === 400) {
- throw new BadBody(json, options.body!);
- }
-
- return request;
+ throw new BadBody(identifier, json, options.body!);
}
checkScopes(required: string[], got: string | string[]) {
diff --git a/libraries/nestjs-libraries/src/integrations/social/facebook.provider.ts b/libraries/nestjs-libraries/src/integrations/social/facebook.provider.ts
index 7332848aa..13c24f745 100644
--- a/libraries/nestjs-libraries/src/integrations/social/facebook.provider.ts
+++ b/libraries/nestjs-libraries/src/integrations/social/facebook.provider.ts
@@ -187,7 +187,8 @@ export class FacebookProvider extends SocialAbstract implements SocialProvider {
description: firstPost.message,
published: true,
}),
- }
+ },
+ 'upload mp4'
)
).json();
@@ -210,7 +211,8 @@ export class FacebookProvider extends SocialAbstract implements SocialProvider {
url: media.url,
published: false,
}),
- }
+ },
+ 'upload images slides'
)
).json();
@@ -235,7 +237,8 @@ export class FacebookProvider extends SocialAbstract implements SocialProvider {
message: firstPost.message,
published: true,
}),
- }
+ },
+ 'finalize upload'
)
).json();
@@ -259,7 +262,8 @@ export class FacebookProvider extends SocialAbstract implements SocialProvider {
: {}),
message: comment.message,
}),
- }
+ },
+ 'add comment'
)
).json();