From c84d8af915aa467301ff5be15bb45e3497f88060 Mon Sep 17 00:00:00 2001 From: Nevo David Date: Wed, 25 Sep 2024 11:56:25 +0700 Subject: [PATCH] feat: console error --- .../database/prisma/posts/posts.service.ts | 11 -------- .../src/integrations/social.abstract.ts | 28 +++++++++++-------- 2 files changed, 16 insertions(+), 23 deletions(-) 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 63487f51..fbd051f2 100644 --- a/libraries/nestjs-libraries/src/database/prisma/posts/posts.service.ts +++ b/libraries/nestjs-libraries/src/database/prisma/posts/posts.service.ts @@ -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; } } diff --git a/libraries/nestjs-libraries/src/integrations/social.abstract.ts b/libraries/nestjs-libraries/src/integrations/social.abstract.ts index 39034f55..eee510db 100644 --- a/libraries/nestjs-libraries/src/integrations/social.abstract.ts +++ b/libraries/nestjs-libraries/src/integrations/social.abstract.ts @@ -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 {} @@ -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;