|
| 1 | +'use client'; |
| 2 | + |
| 3 | +import { useEffect } from 'react'; |
| 4 | +import { AlertCircle, Home, RefreshCw } from 'lucide-react'; |
| 5 | + |
| 6 | +export default function Error({ |
| 7 | + error, |
| 8 | + reset, |
| 9 | +}: { |
| 10 | + error: Error & { digest?: string }; |
| 11 | + reset: () => void; |
| 12 | +}) { |
| 13 | + useEffect(() => { |
| 14 | + // Log the error to an error reporting service |
| 15 | + console.error('Error boundary caught:', error); |
| 16 | + }, [error]); |
| 17 | + |
| 18 | + return ( |
| 19 | + <div className="flex flex-col items-center justify-center min-h-screen px-4 text-center"> |
| 20 | + <div className="max-w-md space-y-6"> |
| 21 | + {/* Icon */} |
| 22 | + <div className="flex justify-center"> |
| 23 | + <div className="rounded-full bg-red-100 dark:bg-red-900/20 p-6"> |
| 24 | + <AlertCircle className="h-16 w-16 text-red-600 dark:text-red-400" /> |
| 25 | + </div> |
| 26 | + </div> |
| 27 | + |
| 28 | + {/* Error Message */} |
| 29 | + <div> |
| 30 | + <h1 className="text-4xl font-bold text-fd-foreground"> |
| 31 | + Oops! Something went wrong |
| 32 | + </h1> |
| 33 | + <p className="mt-2 text-lg text-fd-muted-foreground"> |
| 34 | + We encountered an unexpected error while loading this page. |
| 35 | + </p> |
| 36 | + </div> |
| 37 | + |
| 38 | + {/* Error Details (in development) */} |
| 39 | + {process.env.NODE_ENV === 'development' && error.message && ( |
| 40 | + <div className="text-left bg-fd-muted p-4 rounded-lg max-w-full overflow-auto"> |
| 41 | + <p className="text-sm font-mono text-fd-foreground break-all"> |
| 42 | + {error.message} |
| 43 | + </p> |
| 44 | + {error.digest && ( |
| 45 | + <p className="text-xs text-fd-muted-foreground mt-2"> |
| 46 | + Error ID: {error.digest} |
| 47 | + </p> |
| 48 | + )} |
| 49 | + </div> |
| 50 | + )} |
| 51 | + |
| 52 | + {/* Actions */} |
| 53 | + <div className="flex flex-col sm:flex-row gap-3 justify-center pt-4"> |
| 54 | + <button |
| 55 | + onClick={() => reset()} |
| 56 | + className="inline-flex items-center justify-center gap-2 rounded-lg bg-fd-primary px-6 py-3 text-sm font-medium text-fd-primary-foreground transition-colors hover:bg-fd-primary/90" |
| 57 | + > |
| 58 | + <RefreshCw className="h-4 w-4" /> |
| 59 | + Try Again |
| 60 | + </button> |
| 61 | + <a |
| 62 | + href="/" |
| 63 | + className="inline-flex items-center justify-center gap-2 rounded-lg border border-fd-border px-6 py-3 text-sm font-medium text-fd-foreground transition-colors hover:bg-fd-accent" |
| 64 | + > |
| 65 | + <Home className="h-4 w-4" /> |
| 66 | + Go Home |
| 67 | + </a> |
| 68 | + </div> |
| 69 | + |
| 70 | + {/* Help Text */} |
| 71 | + <div className="pt-8 border-t border-fd-border"> |
| 72 | + <p className="text-sm text-fd-muted-foreground"> |
| 73 | + If this problem persists, please{' '} |
| 74 | + <a |
| 75 | + href="https://github.com/lotivo/sequelize-guard/issues" |
| 76 | + className="text-fd-primary hover:underline" |
| 77 | + target="_blank" |
| 78 | + rel="noopener noreferrer" |
| 79 | + > |
| 80 | + report an issue on GitHub |
| 81 | + </a> |
| 82 | + . |
| 83 | + </p> |
| 84 | + </div> |
| 85 | + </div> |
| 86 | + </div> |
| 87 | + ); |
| 88 | +} |
0 commit comments