Commit
add error boundaries and 404 page
commit
c42885a
3 changed files with +89 and −0
Jump to a changed file
- src/app/error.tsx +28 −0
- src/app/global-error.tsx +39 −0
- src/app/not-found.tsx +22 −0
added src/app/error.tsx +28 −0
| @@ -0,0 +1,28 @@ | ||
| 1 | +'use client'; | |
| 2 | + | |
| 3 | +import { RotateCcw } from 'lucide-react'; | |
| 4 | +import { useEffect } from 'react'; | |
| 5 | +import { Button } from '@/components/ui/button'; | |
| 6 | + | |
| 7 | +export default function Error({ error, reset }: { error: Error & { digest?: string }; reset: () => void }) { | |
| 8 | + useEffect(() => { | |
| 9 | + console.error(error); | |
| 10 | + }, [error]); | |
| 11 | + | |
| 12 | + return ( | |
| 13 | + <div className="container flex min-h-[60vh] flex-col items-center justify-center gap-4 text-center"> | |
| 14 | + <h1 className="text-2xl font-semibold">Something went wrong</h1> | |
| 15 | + <p className="max-w-md text-sm text-muted-foreground"> | |
| 16 | + An unexpected error occurred while loading this page. You can try again, or head back home. | |
| 17 | + </p> | |
| 18 | + <div className="mt-2 flex gap-3"> | |
| 19 | + <Button onClick={reset}> | |
| 20 | + <RotateCcw className="h-4 w-4" /> Try again | |
| 21 | + </Button> | |
| 22 | + <Button variant="ghost" asChild> | |
| 23 | + <a href="/">Back home</a> | |
| 24 | + </Button> | |
| 25 | + </div> | |
| 26 | + </div> | |
| 27 | + ); | |
| 28 | +} |
added src/app/global-error.tsx +39 −0
| @@ -0,0 +1,39 @@ | ||
| 1 | +'use client'; | |
| 2 | + | |
| 3 | +/** Root error boundary. Replaces the whole document, so it ships its own html/body. */ | |
| 4 | +export default function GlobalError({ reset }: { error: Error & { digest?: string }; reset: () => void }) { | |
| 5 | + return ( | |
| 6 | + <html lang="en"> | |
| 7 | + <body | |
| 8 | + style={{ | |
| 9 | + fontFamily: 'system-ui, sans-serif', | |
| 10 | + display: 'flex', | |
| 11 | + minHeight: '100vh', | |
| 12 | + margin: 0, | |
| 13 | + alignItems: 'center', | |
| 14 | + justifyContent: 'center', | |
| 15 | + background: '#0b1020', | |
| 16 | + color: '#e6ecff', | |
| 17 | + }} | |
| 18 | + > | |
| 19 | + <div style={{ textAlign: 'center', padding: 24 }}> | |
| 20 | + <h1 style={{ fontSize: 22, marginBottom: 8 }}>Something went wrong</h1> | |
| 21 | + <p style={{ opacity: 0.7, marginBottom: 16 }}>The application hit an unexpected error.</p> | |
| 22 | + <button | |
| 23 | + onClick={() => reset()} | |
| 24 | + style={{ | |
| 25 | + padding: '8px 16px', | |
| 26 | + borderRadius: 8, | |
| 27 | + border: 'none', | |
| 28 | + background: '#6366f1', | |
| 29 | + color: 'white', | |
| 30 | + cursor: 'pointer', | |
| 31 | + }} | |
| 32 | + > | |
| 33 | + Try again | |
| 34 | + </button> | |
| 35 | + </div> | |
| 36 | + </body> | |
| 37 | + </html> | |
| 38 | + ); | |
| 39 | +} |
added src/app/not-found.tsx +22 −0
| @@ -0,0 +1,22 @@ | ||
| 1 | +import Link from 'next/link'; | |
| 2 | +import { Button } from '@/components/ui/button'; | |
| 3 | + | |
| 4 | +export default function NotFound() { | |
| 5 | + return ( | |
| 6 | + <div className="container flex min-h-[60vh] flex-col items-center justify-center gap-4 text-center"> | |
| 7 | + <p className="text-xs font-medium uppercase tracking-widest text-muted-foreground">404</p> | |
| 8 | + <h1 className="text-3xl font-semibold">This page wandered off</h1> | |
| 9 | + <p className="max-w-md text-muted-foreground"> | |
| 10 | + The debate, demo, or page you were looking for does not exist or has been removed. | |
| 11 | + </p> | |
| 12 | + <div className="mt-2 flex gap-3"> | |
| 13 | + <Button asChild> | |
| 14 | + <Link href="/">Back home</Link> | |
| 15 | + </Button> | |
| 16 | + <Button variant="ghost" asChild> | |
| 17 | + <Link href="/demo">Watch a demo</Link> | |
| 18 | + </Button> | |
| 19 | + </div> | |
| 20 | + </div> | |
| 21 | + ); | |
| 22 | +} |