From 573de24e9c64764988b46810e8a7b672a7efa1c9 Mon Sep 17 00:00:00 2001 From: Nevo David Date: Thu, 5 Dec 2024 16:09:56 +0700 Subject: [PATCH] feat: reddit channel fix --- .../integrations/social/reddit.provider.ts | 36 ++++++++++++------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/libraries/nestjs-libraries/src/integrations/social/reddit.provider.ts b/libraries/nestjs-libraries/src/integrations/social/reddit.provider.ts index aef09e8e..7d6f860c 100644 --- a/libraries/nestjs-libraries/src/integrations/social/reddit.provider.ts +++ b/libraries/nestjs-libraries/src/integrations/social/reddit.provider.ts @@ -76,7 +76,7 @@ export class RedditProvider extends SocialAbstract implements SocialProvider { access_token: accessToken, refresh_token: refreshToken, expires_in: expiresIn, - scope + scope, } = await ( await this.fetch('https://www.reddit.com/api/v1/access_token', { method: 'POST', @@ -300,18 +300,28 @@ export class RedditProvider extends SocialAbstract implements SocialProvider { ) ).json(); - const newData = await ( - await this.fetch( - `https://oauth.reddit.com/${data.subreddit}/api/link_flair_v2`, - { - method: 'GET', - headers: { - Authorization: `Bearer ${accessToken}`, - 'Content-Type': 'application/x-www-form-urlencoded', - }, - } - ) - ).json(); + // eslint-disable-next-line no-async-promise-executor + const newData = await new Promise<{id: string, name: string}[]>(async (res) => { + try { + const flair = await ( + await this.fetch( + `https://oauth.reddit.com/${data.subreddit}/api/link_flair_v2`, + { + method: 'GET', + headers: { + Authorization: `Bearer ${accessToken}`, + 'Content-Type': 'application/x-www-form-urlencoded', + }, + } + ) + ).json(); + + res(flair); + } + catch (err) { + return res([]); + } + }); return { subreddit: data.subreddit,