Skip to content

Commit

Permalink
[Slack connector deletion] Skip app uninstall if nango connection unk…
Browse files Browse the repository at this point in the history
…nown
  • Loading branch information
philipperolet committed Jan 24, 2024
1 parent 0a76a1e commit 7dd4391
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions connectors/src/connectors/slack/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { ModelId } from "@dust-tt/types";
import { WebClient } from "@slack/web-api";
import { AxiosError } from "axios";
import PQueue from "p-queue";

import type {
Expand Down Expand Up @@ -248,9 +249,8 @@ export async function uninstallSlack(nangoConnectionId: string) {
throw new Error("SLACK_CLIENT_SECRET is not defined");
}

const slackAccessToken = await getSlackAccessToken(nangoConnectionId);

try {
const slackAccessToken = await getSlackAccessToken(nangoConnectionId);
const slackClient = await getSlackClient(slackAccessToken);
await slackClient.auth.test();
const deleteRes = await slackClient.apps.uninstall({
Expand All @@ -265,7 +265,20 @@ export async function uninstallSlack(nangoConnectionId: string) {
);
}
} catch (e) {
if (e instanceof ExternalOauthTokenError) {
if (
e instanceof AxiosError &&
e.response?.status === 400 &&
e.response?.data?.type === "unknown_connection"
) {
logger.info(
{
nangoConnectionId,
error: `Unknown nango connection: ${e.response.data.error}`,
},
"Unknown nango connection, skipping uninstallation of the Slack app"
);
return new Ok(undefined);
} else if (e instanceof ExternalOauthTokenError) {
logger.info(
{
nangoConnectionId,
Expand Down

0 comments on commit 7dd4391

Please sign in to comment.