Skip to content

Commit

Permalink
Mark connectors as errored. (#3583)
Browse files Browse the repository at this point in the history
* Adding cli to set connector error

* Allow marking a connector as errored

* Clean up after self review
  • Loading branch information
lasryaric authored Feb 5, 2024
1 parent 5287c2e commit ba9d405
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
14 changes: 14 additions & 0 deletions connectors/src/admin/cli.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { isConnectorError } from "@dust-tt/types";
import parseArgs from "minimist";
import PQueue from "p-queue";
import readline from "readline";
Expand Down Expand Up @@ -130,6 +131,18 @@ const connectors = async (command: string, args: parseArgs.ParsedArgs) => {
return;
}

case "set-error": {
if (!args.error) {
throw new Error("Missing --error argument");
}
if (!isConnectorError(args.error)) {
throw new Error(`Invalid error: ${args.error}`);
}
connector.errorType = args.error;
await connector.save();
return;
}

case "restart": {
await throwOnError(
STOP_CONNECTOR_BY_TYPE[provider](connector.id.toString())
Expand Down Expand Up @@ -263,6 +276,7 @@ const notion = async (command: string, args: parseArgs.ParsedArgs) => {
const connectors = await Connector.findAll({
where: {
type: "notion",
errorType: null,
},
});
for (const connector of connectors) {
Expand Down
27 changes: 25 additions & 2 deletions front/components/data_source/DataSourceSyncChip.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Chip } from "@dust-tt/sparkle";
import type { ConnectorType } from "@dust-tt/types";
import { assertNever } from "@dust-tt/types";
import { useEffect, useState } from "react";

import { CONNECTOR_CONFIGURATIONS } from "@app/lib/connector_providers";
import { timeAgoFrom } from "@app/lib/utils";

export default function ConnectorSyncingChip({
Expand All @@ -19,8 +21,29 @@ export default function ConnectorSyncingChip({
if (connector.errorType) {
return (
<Chip color="warning">
Oops! It seems that our access to your account has been revoked. Please
re-authorize this Data Source to keep your data up to date on Dust.
{(() => {
switch (connector.errorType) {
case "oauth_token_revoked":
return (
<>
Oops! It seems that our access to your account has been
revoked. Please re-authorize this Data Source to keep your
data up to date on Dust.
</>
);
case "third_party_internal_error":
return (
<>
We have ecountered an error talking to{" "}
{CONNECTOR_CONFIGURATIONS[connector.type].name}. We sent you
an email with more details to resolve the issue.
</>
);
default:
assertNever(connector.errorType);
}
return <></>;
})()}
</Chip>
);
} else if (!connector.lastSyncSuccessfulTime) {
Expand Down
10 changes: 9 additions & 1 deletion types/src/front/lib/connectors_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@ const {

export type ConnectorsAPIResponse<T> = Result<T, ConnectorsAPIError>;
export type ConnectorSyncStatus = "succeeded" | "failed";
export type ConnectorErrorType = "oauth_token_revoked";
const CONNECTORS_ERROR_TYPES = [
"oauth_token_revoked",
"third_party_internal_error",
] as const;

export type ConnectorErrorType = (typeof CONNECTORS_ERROR_TYPES)[number];
export function isConnectorError(val: string): val is ConnectorErrorType {
return (CONNECTORS_ERROR_TYPES as unknown as string[]).includes(val);
}

export const CONNECTOR_PROVIDERS_USING_NANGO = [
"confluence",
Expand Down

0 comments on commit ba9d405

Please sign in to comment.