mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-06 07:26:45 +00:00
feat: added error boundary
This commit is contained in:
@@ -1,9 +1,11 @@
|
|||||||
import React, { ErrorInfo, ReactNode } from "react";
|
import React, { ErrorInfo, ReactNode, useEffect } from "react";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { useRouter } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
import { faBugs } from "@fortawesome/free-solid-svg-icons";
|
import { faBugs, faHome } from "@fortawesome/free-solid-svg-icons";
|
||||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||||
|
|
||||||
|
import { Button } from "@app/components/v2";
|
||||||
|
|
||||||
interface ErrorBoundaryProps {
|
interface ErrorBoundaryProps {
|
||||||
children: ReactNode;
|
children: ReactNode;
|
||||||
}
|
}
|
||||||
@@ -14,12 +16,22 @@ interface ErrorBoundaryState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const ErrorPage = ({ error }: { error: Error | null }) => {
|
const ErrorPage = ({ error }: { error: Error | null }) => {
|
||||||
|
const [orgId, setOrgId] = React.useState<string | null>(null);
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const currentUrl = router?.asPath?.split("?")?.[0];
|
const currentUrl = router?.asPath?.split("?")?.[0];
|
||||||
|
|
||||||
|
// Workaround: Fixes localStorage not being available in the error boundary until the next render.
|
||||||
|
useEffect(() => {
|
||||||
|
const savedOrgId = localStorage.getItem("orgData.id");
|
||||||
|
|
||||||
|
if (savedOrgId) {
|
||||||
|
setOrgId(savedOrgId);
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex h-screen w-screen items-center justify-center bg-mineshaft-900">
|
<div className="flex h-screen w-screen items-center justify-center bg-mineshaft-900">
|
||||||
<div className="flex max-w-md flex-col rounded-md border border-mineshaft-600 bg-mineshaft-800 p-6 text-center text-mineshaft-200">
|
<div className="flex max-w-md flex-col rounded-md border border-mineshaft-600 bg-mineshaft-800 p-8 text-center text-mineshaft-200">
|
||||||
<FontAwesomeIcon icon={faBugs} className="my-2 inline text-6xl" />
|
<FontAwesomeIcon icon={faBugs} className="my-2 inline text-6xl" />
|
||||||
<p>
|
<p>
|
||||||
Something went wrong. Please contact{" "}
|
Something went wrong. Please contact{" "}
|
||||||
@@ -44,23 +56,22 @@ const ErrorPage = ({ error }: { error: Error | null }) => {
|
|||||||
if the issue persists.
|
if the issue persists.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<div className="my-4 h-px w-full bg-mineshaft-600" />
|
{orgId && (
|
||||||
|
<Button className="mt-4" size="xs" onClick={() => router.push(`/org/${orgId}`)}>
|
||||||
|
<FontAwesomeIcon icon={faHome} className="mr-2" />
|
||||||
|
Back To Home
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
|
||||||
{error?.message && (
|
{error?.message && (
|
||||||
<div className="space-y-2">
|
<>
|
||||||
<div>
|
<div className="my-4 h-px w-full bg-mineshaft-600" />
|
||||||
<p>Error details:</p>
|
<p className="thin-scrollbar max-h-44 w-full overflow-auto text-ellipsis rounded-md bg-mineshaft-700 p-2">
|
||||||
<p className="text-xs italic opacity-70">
|
<code className="text-xs">
|
||||||
Please provide this error message when contacting support, as it will help us
|
|
||||||
diagnose the issue at hand.
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<p className="max-h-44 w-full overflow-auto text-ellipsis rounded-md bg-mineshaft-700">
|
|
||||||
<code className="p-2 text-xs">
|
|
||||||
{currentUrl}, {error.message}
|
{currentUrl}, {error.message}
|
||||||
</code>
|
</code>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user