Skip to content

Commit

Permalink
connectors: rename ExternalOAuthTokenError (#6389)
Browse files Browse the repository at this point in the history
  • Loading branch information
spolu authored Jul 22, 2024
1 parent e96ddc3 commit f4e9b12
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 25 deletions.
4 changes: 2 additions & 2 deletions connectors/migrations/20240529_clean_gdrive_folders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
getAuthObject,
getDocumentId,
} from "@connectors/connectors/google_drive/temporal/utils";
import { ExternalOauthTokenError } from "@connectors/lib/error";
import { ExternalOAuthTokenError } from "@connectors/lib/error";
import {
GoogleDriveFiles,
GoogleDriveFolders,
Expand Down Expand Up @@ -63,7 +63,7 @@ async function main() {
try {
return await getAuthObject(connector.connectionId);
} catch (e) {
if (e instanceof ExternalOauthTokenError) {
if (e instanceof ExternalOAuthTokenError) {
logger.info(
{ connectorId, folderId },
`Auth revoked, deleting folder (live: ${LIVE})`
Expand Down
8 changes: 4 additions & 4 deletions connectors/src/connectors/github/lib/github_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
GetRepoDiscussionsPayloadSchema,
} from "@connectors/connectors/github/lib/github_graphql";
import { apiConfig } from "@connectors/lib/api/config";
import { ExternalOauthTokenError } from "@connectors/lib/error";
import { ExternalOAuthTokenError } from "@connectors/lib/error";
import { getOAuthConnectionAccessTokenWithThrow } from "@connectors/lib/oauth";
import logger from "@connectors/logger/logger";

Expand Down Expand Up @@ -102,7 +102,7 @@ export async function installationIdFromConnectionId(
export async function getReposPage(
connectionId: string,
page: number
): Promise<Result<GithubRepo[], ExternalOauthTokenError>> {
): Promise<Result<GithubRepo[], ExternalOAuthTokenError>> {
try {
const octokit = await getOctokit(connectionId);

Expand All @@ -128,7 +128,7 @@ export async function getReposPage(
);
} catch (e) {
if (isGithubRequestErrorNotFound(e)) {
return new Err(new ExternalOauthTokenError(e));
return new Err(new ExternalOAuthTokenError(e));
}
throw e;
}
Expand Down Expand Up @@ -691,7 +691,7 @@ export async function processRepository({
).data;
} catch (err) {
if (isGithubRequestErrorNotFound(err)) {
return new Err(new ExternalOauthTokenError(err));
return new Err(new ExternalOAuthTokenError(err));
}

throw err;
Expand Down
4 changes: 2 additions & 2 deletions connectors/src/connectors/github/temporal/activities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
renderMarkdownSection,
upsertToDatasource,
} from "@connectors/lib/data_sources";
import { ExternalOauthTokenError } from "@connectors/lib/error";
import { ExternalOAuthTokenError } from "@connectors/lib/error";
import {
GithubCodeDirectory,
GithubCodeFile,
Expand Down Expand Up @@ -961,7 +961,7 @@ export async function githubCodeSyncActivity({
Context.current().heartbeat();

if (repoRes.isErr()) {
if (repoRes.error instanceof ExternalOauthTokenError) {
if (repoRes.error instanceof ExternalOAuthTokenError) {
localLogger.info(
{ err: repoRes.error },
"Missing Github repository tarball: Garbage collecting repo."
Expand Down
4 changes: 2 additions & 2 deletions connectors/src/connectors/intercom/lib/intercom_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {
IntercomTeamType,
} from "@connectors/connectors/intercom/lib/types";
import {
ExternalOauthTokenError,
ExternalOAuthTokenError,
ProviderWorkflowError,
} from "@connectors/lib/error";
import logger from "@connectors/logger/logger";
Expand Down Expand Up @@ -69,7 +69,7 @@ async function queryIntercomAPI({
const error = response.errors[0];
// This error is thrown when we are dealing with a revoked OAuth token.
if (error.code === "unauthorized") {
throw new ExternalOauthTokenError();
throw new ExternalOAuthTokenError();
}
// We return null for 404 errors.
if (error.code === "not_found") {
Expand Down
4 changes: 2 additions & 2 deletions connectors/src/connectors/notion/lib/notion_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { stringify } from "csv-stringify";
import type { Logger } from "pino";

import { cacheGet, cacheSet } from "@connectors/lib/cache";
import { ExternalOauthTokenError } from "@connectors/lib/error";
import { ExternalOAuthTokenError } from "@connectors/lib/error";
import mainLogger from "@connectors/logger/logger";

const logger = mainLogger.child({ provider: "notion" });
Expand All @@ -54,7 +54,7 @@ async function wrapNotionAPITokenErrors<T>(
} catch (err) {
if (isNotionClientError(err)) {
if (err.code === "unauthorized") {
throw new ExternalOauthTokenError(err);
throw new ExternalOAuthTokenError(err);
}
}

Expand Down
6 changes: 3 additions & 3 deletions connectors/src/connectors/slack/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
getSlackClient,
} from "@connectors/connectors/slack/lib/slack_client";
import { launchSlackSyncWorkflow } from "@connectors/connectors/slack/temporal/client.js";
import { ExternalOauthTokenError, NangoError } from "@connectors/lib/error";
import { ExternalOAuthTokenError, NangoError } from "@connectors/lib/error";
import { SlackChannel } from "@connectors/lib/models/slack";
import { terminateAllWorkflowsForConnectorId } from "@connectors/lib/temporal";
import logger from "@connectors/logger/logger";
Expand Down Expand Up @@ -376,7 +376,7 @@ export class SlackConnectorManager extends BaseConnectorManager<SlackConfigurati

return new Ok(resources);
} catch (e) {
if (e instanceof ExternalOauthTokenError) {
if (e instanceof ExternalOAuthTokenError) {
logger.error({ connectorId: this.connectorId }, "Slack token invalid");
return new Err(
new Error("Slack token invalid. Please re-authorize Slack.")
Expand Down Expand Up @@ -746,7 +746,7 @@ export async function uninstallSlack(connectionId: string) {
"Unknown nango connection, skipping uninstallation of the Slack app"
);
return new Ok(undefined);
} else if (e instanceof ExternalOauthTokenError) {
} else if (e instanceof ExternalOAuthTokenError) {
logger.info(
{
connectionId: connectionId,
Expand Down
4 changes: 2 additions & 2 deletions connectors/src/connectors/slack/lib/slack_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {
import { ErrorCode, WebClient } from "@slack/web-api";

import {
ExternalOauthTokenError,
ExternalOAuthTokenError,
ProviderWorkflowError,
} from "@connectors/lib/error";
import { getOAuthConnectionAccessTokenWithThrow } from "@connectors/lib/oauth";
Expand Down Expand Up @@ -93,7 +93,7 @@ export async function getSlackClient(
platformError.data.error
)
) {
throw new ExternalOauthTokenError();
throw new ExternalOAuthTokenError();
}
}
throw e;
Expand Down
4 changes: 2 additions & 2 deletions connectors/src/lib/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ export interface NotFoundError extends HTTPError {
}

// This error is thrown when we are dealing with a revoked OAuth token.
export class ExternalOauthTokenError extends Error {
export class ExternalOAuthTokenError extends Error {
constructor(readonly innerError?: Error) {
super(innerError?.message);
this.name = "ExternalOauthTokenError";
this.name = "ExternalOAuthTokenError";
}
}

Expand Down
4 changes: 2 additions & 2 deletions connectors/src/lib/nango_helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import axios from "axios";

import {
DustConnectorWorkflowError,
ExternalOauthTokenError,
ExternalOAuthTokenError,
NANGO_ERROR_TYPES,
NangoError,
} from "@connectors/lib/error";
Expand Down Expand Up @@ -37,7 +37,7 @@ class CustomNango extends Nango {
) &&
errorText.includes("invalid_grant")
) {
throw new ExternalOauthTokenError();
throw new ExternalOAuthTokenError();
}
const errorType = e.response.data.type;
if (NANGO_ERROR_TYPES.includes(errorType)) {
Expand Down
4 changes: 2 additions & 2 deletions connectors/src/lib/oauth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getOAuthConnectionAccessToken } from "@dust-tt/types";
import type { LoggerInterface } from "@dust-tt/types/dist/shared/logger";

import { apiConfig } from "@connectors/lib/api/config";
import { ExternalOauthTokenError } from "@connectors/lib/error";
import { ExternalOAuthTokenError } from "@connectors/lib/error";

// This function is used to discreminate between a new OAuth connection and an old Nango/Github
// connection. It is used to support dual-use while migrating and should be unused by a connector
Expand Down Expand Up @@ -44,7 +44,7 @@ export async function getOAuthConnectionAccessTokenWithThrow({
);

if (tokRes.error.code === "token_revoked_error") {
throw new ExternalOauthTokenError();
throw new ExternalOAuthTokenError();
} else {
throw new Error(`Error retrieving access token from ${provider}`);
}
Expand Down
4 changes: 2 additions & 2 deletions connectors/src/lib/temporal_monitoring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type { Logger } from "@connectors/logger/logger";
import type logger from "@connectors/logger/logger";
import { statsDClient } from "@connectors/logger/withlogging";

import { DustConnectorWorkflowError, ExternalOauthTokenError } from "./error";
import { DustConnectorWorkflowError, ExternalOAuthTokenError } from "./error";
import { syncFailed } from "./sync_status";
import { cancelWorkflow, getConnectorId } from "./temporal";

Expand Down Expand Up @@ -133,7 +133,7 @@ export class ActivityInboundLogInterceptor
);
}

if (err instanceof ExternalOauthTokenError) {
if (err instanceof ExternalOAuthTokenError) {
// We have a connector working on an expired token, we need to cancel the workflow.
const { workflowId } = this.context.info.workflowExecution;

Expand Down

0 comments on commit f4e9b12

Please sign in to comment.