From b2d68887ac7c9f82dd5a40481d64af538896b928 Mon Sep 17 00:00:00 2001 From: Nevo David Date: Fri, 1 Aug 2025 11:14:27 +0700 Subject: [PATCH] feat: remove try-catch from pinterest --- .../integrations/social/pinterest.provider.ts | 95 +++++++++---------- 1 file changed, 45 insertions(+), 50 deletions(-) diff --git a/libraries/nestjs-libraries/src/integrations/social/pinterest.provider.ts b/libraries/nestjs-libraries/src/integrations/social/pinterest.provider.ts index 0ce6e1b4..8bfc048a 100644 --- a/libraries/nestjs-libraries/src/integrations/social/pinterest.provider.ts +++ b/libraries/nestjs-libraries/src/integrations/social/pinterest.provider.ts @@ -212,57 +212,52 @@ export class PinterestProvider path: m.path, })); - try { - const { id: pId } = await ( - await this.fetch('https://api.pinterest.com/v5/pins', { - method: 'POST', - headers: { - Authorization: `Bearer ${accessToken}`, - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ - ...(postDetails?.[0]?.settings.link - ? { link: postDetails?.[0]?.settings.link } - : {}), - ...(postDetails?.[0]?.settings.title - ? { title: postDetails?.[0]?.settings.title } - : {}), - description: postDetails?.[0]?.message, - ...(postDetails?.[0]?.settings.dominant_color - ? { dominant_color: postDetails?.[0]?.settings.dominant_color } - : {}), - board_id: postDetails?.[0]?.settings.board, - media_source: mediaId - ? { - source_type: 'video_id', - media_id: mediaId, - cover_image_url: picture?.path, - } - : mapImages?.length === 1 - ? { - source_type: 'image_url', - url: mapImages?.[0]?.path, - } - : { - source_type: 'multiple_image_urls', - items: mapImages, - }, - }), - }) - ).json(); - - return [ - { - id: postDetails?.[0]?.id, - postId: pId, - releaseURL: `https://www.pinterest.com/pin/${pId}`, - status: 'success', + const { id: pId } = await ( + await this.fetch('https://api.pinterest.com/v5/pins', { + method: 'POST', + headers: { + Authorization: `Bearer ${accessToken}`, + 'Content-Type': 'application/json', }, - ]; - } catch (err) { - console.log(err); - return []; - } + body: JSON.stringify({ + ...(postDetails?.[0]?.settings.link + ? { link: postDetails?.[0]?.settings.link } + : {}), + ...(postDetails?.[0]?.settings.title + ? { title: postDetails?.[0]?.settings.title } + : {}), + description: postDetails?.[0]?.message, + ...(postDetails?.[0]?.settings.dominant_color + ? { dominant_color: postDetails?.[0]?.settings.dominant_color } + : {}), + board_id: postDetails?.[0]?.settings.board, + media_source: mediaId + ? { + source_type: 'video_id', + media_id: mediaId, + cover_image_url: picture?.path, + } + : mapImages?.length === 1 + ? { + source_type: 'image_url', + url: mapImages?.[0]?.path, + } + : { + source_type: 'multiple_image_urls', + items: mapImages, + }, + }), + }) + ).json(); + + return [ + { + id: postDetails?.[0]?.id, + postId: pId, + releaseURL: `https://www.pinterest.com/pin/${pId}`, + status: 'success', + }, + ]; } async analytics(