Skip to content

Commit

Permalink
Properly delete a Slack connector (#2486)
Browse files Browse the repository at this point in the history
  • Loading branch information
lasryaric authored Nov 10, 2023
1 parent 30518fa commit 2b83cd3
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions connectors/src/connectors/slack/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { WebClient } from "@slack/web-api";
import {
CodedError,
ErrorCode,
WebAPIPlatformError,
WebClient,
} from "@slack/web-api";
import PQueue from "p-queue";

import { ConnectorPermissionRetriever } from "@connectors/connectors/interface";
Expand Down Expand Up @@ -235,8 +240,9 @@ export async function cleanupSlackConnector(
return new Err(new Error("SLACK_CLIENT_SECRET is not defined"));
}

const slackClient = await getSlackClient(connector.id);
try {
const slackClient = await getSlackClient(connector.id);
await slackClient.auth.test();
const deleteRes = await slackClient.apps.uninstall({
client_id: SLACK_CLIENT_ID,
client_secret: SLACK_CLIENT_SECRET,
Expand All @@ -249,10 +255,25 @@ export async function cleanupSlackConnector(
);
}
} catch (e) {
logger.error(
{ connectorId: connectorId, error: e },
"Could not uninstall the Slack app from the user's workspace."
);
const slackError = e as CodedError;
let shouldThrow = true;

if (slackError.code === ErrorCode.PlatformError) {
const platformError = e as WebAPIPlatformError;
if (platformError.data.error === "account_inactive") {
shouldThrow = false;
logger.info(
{
connectorId,
},
`Slack auth is invalid, skipping uninstallation of the Slack app`
);
}
}

if (shouldThrow) {
throw e;
}
}

const nangoRes = await nangoDeleteConnection(
Expand Down

0 comments on commit 2b83cd3

Please sign in to comment.