From fc349942b50d03c839098ddd7d037cf2482b0885 Mon Sep 17 00:00:00 2001 From: Nevo David Date: Mon, 5 Jan 2026 21:30:04 +0700 Subject: [PATCH] feat: fix refresh token --- .../src/integrations/social.abstract.ts | 5 +++-- .../src/integrations/social/threads.provider.ts | 13 +++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/libraries/nestjs-libraries/src/integrations/social.abstract.ts b/libraries/nestjs-libraries/src/integrations/social.abstract.ts index a3dd40e7..150d642a 100644 --- a/libraries/nestjs-libraries/src/integrations/social.abstract.ts +++ b/libraries/nestjs-libraries/src/integrations/social.abstract.ts @@ -135,8 +135,9 @@ export abstract class SocialAbstract { } if ( - request.status === 401 && - (handleError?.type === 'refresh-token' || !handleError) + (request.status === 401 && + (handleError?.type === 'refresh-token' || !handleError)) || + handleError?.type === 'refresh-token' ) { throw new RefreshToken( identifier, diff --git a/libraries/nestjs-libraries/src/integrations/social/threads.provider.ts b/libraries/nestjs-libraries/src/integrations/social/threads.provider.ts index 5c852c4b..fa8e0dc2 100644 --- a/libraries/nestjs-libraries/src/integrations/social/threads.provider.ts +++ b/libraries/nestjs-libraries/src/integrations/social/threads.provider.ts @@ -32,6 +32,19 @@ export class ThreadsProvider extends SocialAbstract implements SocialProvider { return 500; } + override handleErrors(body: string): + | { + type: 'refresh-token' | 'bad-body'; + value: string; + } + | undefined { + if (body.includes('Error validating access token')) { + return { type: 'refresh-token', value: 'Threads access token expired' }; + } + + return undefined; + } + async refreshToken(refresh_token: string): Promise { const { access_token } = await ( await this.fetch(