Add error boundaries for auth and assume

Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
Émile Ré
2026-02-10 13:06:56 +04:00
parent 583148eb5f
commit ab497ad6a7
3 changed files with 43 additions and 28 deletions

View File

@@ -0,0 +1,22 @@
import { AssumptionRequiredError, UnAuthenticatedError } from "@probo/relay";
import { Navigate, useLocation, useRouteError } from "react-router";
import { useOrganizationId } from "#/hooks/useOrganizationId";
import { PageError } from "./PageError";
export function OrganizationErrorBoundary() {
const error = useRouteError();
const location = useLocation();
const organizationId = useOrganizationId();
if (error instanceof UnAuthenticatedError) {
return <Navigate to="/auth/login" state={{ from: location.pathname }} />;
}
if (error instanceof AssumptionRequiredError) {
return <Navigate to="/auth/login" state={{ from: location.pathname, organizationId }} />;
}
return <PageError error={error instanceof Error ? error : new Error("unknown error")} />;
}

View File

@@ -0,0 +1,15 @@
import { UnAuthenticatedError } from "@probo/relay";
import { Navigate, useLocation, useRouteError } from "react-router";
import { PageError } from "./PageError";
export function RootErrorBoundary() {
const error = useRouteError();
const location = useLocation();
if (error instanceof UnAuthenticatedError) {
return <Navigate to="/auth/login" state={{ from: location.pathname }} />;
}
return <PageError error={error instanceof Error ? error : new Error("unknown error")} />;
}