From 178619d43b4fc4e26907dbc374c1b7ffbd064006 Mon Sep 17 00:00:00 2001 From: Gilad Resisi Date: Mon, 6 Jul 2026 19:01:21 +0700 Subject: [PATCH] fix(integrations): send a single notification when a token refresh fails MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a token refresh fails, refreshProcess sent the refresh-error notification (with the failure cause) and then called disconnectChannel, which sends the same notification again without the cause. Every failed refresh therefore emailed the user twice: once titled "Could not refresh your channel " and once "Could not refresh your channel". Drop the disconnectChannel call from the failure branch: the refreshNeeded call two lines earlier already sets the same flag disconnectChannel would, so the only thing it added was the duplicate email. disconnectChannel itself is unchanged for its other callers. Reproduced by triggering a post on an Instagram channel holding an invalid token (refresh fails since the provider cannot refresh) — two emails arrived for the single failure. After the fix, the same scenario produces exactly one email (the one including the failure cause), and the channel is still flagged as needing reconnection. Co-Authored-By: Claude Fable 5 --- .../src/integrations/refresh.integration.service.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/libraries/nestjs-libraries/src/integrations/refresh.integration.service.ts b/libraries/nestjs-libraries/src/integrations/refresh.integration.service.ts index 0689bdc603..bf59c32bb1 100644 --- a/libraries/nestjs-libraries/src/integrations/refresh.integration.service.ts +++ b/libraries/nestjs-libraries/src/integrations/refresh.integration.service.ts @@ -78,6 +78,10 @@ export class RefreshIntegrationService { .catch((err) => false); if (!refresh || !refresh.accessToken) { + // informAboutRefreshError (with the failure cause) already notifies + // the user, and refreshNeeded sets the same flag disconnectChannel + // would — calling disconnectChannel here sent a second, cause-less + // copy of the same email for every failed refresh. await this._integrationService.refreshNeeded( integration.organizationId, integration.id @@ -89,11 +93,6 @@ export class RefreshIntegrationService { cause ); - await this._integrationService.disconnectChannel( - integration.organizationId, - integration - ); - return false; }