Skip to content

Commit

Permalink
feat: console error
Browse files Browse the repository at this point in the history
  • Loading branch information
Nevo David committed Sep 25, 2024
1 parent b4beee6 commit c84d8af
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -290,17 +290,6 @@ export class PostsService {
return this.postSocial(integration, posts, true);
}

if (
err instanceof BadBody &&
process.env.EMAIL_FROM_ADDRESS === 'nevo@postiz.com'
) {
await this._notificationService.sendEmail(
'nevo@positz.com',
'Bad body',
JSON.stringify(err.body)
);
}

throw err;
}
}
Expand Down
28 changes: 16 additions & 12 deletions libraries/nestjs-libraries/src/integrations/social.abstract.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
export class RefreshToken {}
export class RefreshToken {
constructor(public json: string, public body: BodyInit) {}
}
export class BadBody {
constructor(public body: BodyInit) {
}
constructor(public json: string, public body: BodyInit) {}
}

export class NotEnoughScopes {}
Expand All @@ -10,20 +11,23 @@ export abstract class SocialAbstract {
async fetch(url: string, options: RequestInit = {}) {
const request = await fetch(url, options);

if (request.status !== 200 && request.status !== 201) {
try {
console.log(await request.json());
}
catch (err) {
console.log('skip');
}
if (request.status === 200 || request.status === 201) {
return request;
}

let json = '{}';
try {
json = await request.json();
} catch (err) {
json = '{}';
}

if (request.status === 401) {
throw new RefreshToken();
throw new RefreshToken(json, options.body!);
}

if (request.status === 400) {
throw new BadBody(options.body!);
throw new BadBody(json, options.body!);
}

return request;
Expand Down

0 comments on commit c84d8af

Please sign in to comment.