Fix indexing status page crashing

This commit is contained in:
Weves 2024-06-06 18:17:27 -07:00 committed by Chris Weaver
parent 09da456bba
commit f6fb963419
2 changed files with 13 additions and 7 deletions

View File

@ -4,7 +4,7 @@ import useSWR from "swr";
import { LoadingAnimation } from "@/components/Loading";
import { NotebookIcon } from "@/components/icons/icons";
import { fetcher } from "@/lib/fetcher";
import { errorHandlingFetcher, fetcher } from "@/lib/fetcher";
import { ConnectorIndexingStatus } from "@/lib/types";
import { CCPairIndexingStatusTable } from "./CCPairIndexingStatusTable";
import { AdminPageTitle } from "@/components/admin/Title";
@ -15,10 +15,10 @@ function Main() {
const {
data: indexAttemptData,
isLoading: indexAttemptIsLoading,
error: indexAttemptIsError,
error: indexAttemptError,
} = useSWR<ConnectorIndexingStatus<any, any>[]>(
"/api/manage/admin/connector/indexing-status",
fetcher,
errorHandlingFetcher,
{ refreshInterval: 10000 } // 10 seconds
);
@ -26,15 +26,19 @@ function Main() {
return <LoadingAnimation text="" />;
}
if (indexAttemptIsError || !indexAttemptData) {
return <div className="text-red-600">Error loading indexing history.</div>;
if (indexAttemptError || !indexAttemptData) {
return (
<div className="text-error">
{indexAttemptError?.info?.detail || "Error loading indexing history."}
</div>
);
}
if (indexAttemptData.length === 0) {
return (
<Text>
It looks like you don&apos;t have any connectors setup yet. Visit the{" "}
<Link className="text-blue-500" href="/admin/add-connector">
<Link className="text-link" href="/admin/add-connector">
Add Connector
</Link>{" "}
page to get started!

View File

@ -11,11 +11,13 @@ class FetchError extends Error {
}
}
const DEFAULT_ERROR_MSG = "An error occurred while fetching the data.";
export const errorHandlingFetcher = async (url: string) => {
const res = await fetch(url);
if (!res.ok) {
const error = new FetchError(
"An error occurred while fetching the data.",
DEFAULT_ERROR_MSG,
res.status,
await res.json()
);