Add error boundaries for auth and assume
Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
22
apps/console/src/components/OrganizationErrorBoundary.tsx
Normal file
22
apps/console/src/components/OrganizationErrorBoundary.tsx
Normal 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")} />;
|
||||
}
|
||||
15
apps/console/src/components/RootErrorBoundary.tsx
Normal file
15
apps/console/src/components/RootErrorBoundary.tsx
Normal 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")} />;
|
||||
}
|
||||
Reference in New Issue
Block a user