mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-04-27 09:46:25 +02:00
Closes #1195. Adds `surfsense_web/app/dashboard/error.tsx` so unhandled errors in any dashboard route render inside the dashboard layout (sidebar/nav stay visible) instead of blowing out to the root-level error page. `reset()` now retries just the failed segment. Follows the same PostHog capture pattern as the root error.tsx and adds a secondary "Go to dashboard home" link for recovery when `reset()` doesn't help.
44 lines
1.2 KiB
TypeScript
44 lines
1.2 KiB
TypeScript
"use client";
|
|
|
|
import Link from "next/link";
|
|
import { useEffect } from "react";
|
|
|
|
export default function DashboardError({
|
|
error,
|
|
reset,
|
|
}: {
|
|
error: globalThis.Error & { digest?: string };
|
|
reset: () => void;
|
|
}) {
|
|
useEffect(() => {
|
|
import("posthog-js")
|
|
.then(({ default: posthog }) => {
|
|
posthog.captureException(error);
|
|
})
|
|
.catch(() => {});
|
|
}, [error]);
|
|
|
|
return (
|
|
<div className="flex flex-1 flex-col items-center justify-center gap-4 p-8 text-center">
|
|
<h2 className="text-xl font-semibold">Something went wrong</h2>
|
|
<p className="text-muted-foreground max-w-md">
|
|
An error occurred in this section. Your dashboard is still available.
|
|
</p>
|
|
<div className="flex gap-2">
|
|
<button
|
|
type="button"
|
|
onClick={reset}
|
|
className="rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground hover:bg-primary/90 transition-colors"
|
|
>
|
|
Try again
|
|
</button>
|
|
<Link
|
|
href="/dashboard"
|
|
className="rounded-md border border-input bg-background px-4 py-2 text-sm font-medium hover:bg-accent hover:text-accent-foreground transition-colors"
|
|
>
|
|
Go to dashboard home
|
|
</Link>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|