forked from StellarSplit/StellarSplit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRouteErrorBoundary.tsx
More file actions
68 lines (62 loc) · 2.05 KB
/
Copy pathRouteErrorBoundary.tsx
File metadata and controls
68 lines (62 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import {
Link,
isRouteErrorResponse,
useLocation,
useRouteError,
} from "react-router-dom";
function getErrorMessage(error: unknown): string {
if (isRouteErrorResponse(error)) {
if (typeof error.data === "string" && error.data.trim()) return error.data;
if (typeof error.statusText === "string" && error.statusText.trim())
return error.statusText;
return `Request failed (${error.status})`;
}
if (error instanceof Error) return error.message;
if (typeof error === "string") return error;
return "Something went wrong while loading the current screen.";
}
export default function RouteErrorBoundary() {
const error = useRouteError();
const { pathname } = useLocation();
const message = getErrorMessage(error);
return (
<section
className="mx-auto flex min-h-[calc(100vh-3.5rem)] w-full max-w-4xl items-center justify-center p-6 sm:p-8"
role="alert"
aria-live="polite"
data-testid="route-error-boundary"
>
<div className="w-full rounded-3xl border border-theme bg-card-theme p-6 shadow-sm sm:p-8">
<p className="text-xs font-semibold uppercase tracking-[0.28em] text-accent">
Page Error
</p>
<h1 className="mt-3 text-2xl font-semibold text-theme">
We could not render this page
</h1>
<p className="mt-3 max-w-2xl text-sm leading-6 text-muted-theme">
{message}
</p>
<div className="mt-6 flex flex-wrap gap-3">
<a
href={pathname}
className="rounded-full bg-accent px-4 py-2 text-sm font-semibold text-white"
>
Try Again
</a>
<Link
to="/dashboard"
className="rounded-full border border-theme px-4 py-2 text-sm font-semibold text-theme"
>
Open Dashboard
</Link>
<Link
to="/"
className="rounded-full border border-theme px-4 py-2 text-sm font-semibold text-theme"
>
Go Home
</Link>
</div>
</div>
</section>
);
}