|
| 1 | +'use client'; |
| 2 | + |
| 3 | +import { useEffect } from 'react'; |
| 4 | + |
| 5 | +export default function Error({ |
| 6 | + error, |
| 7 | + reset, |
| 8 | +}: { |
| 9 | + error: Error & { digest?: string }; |
| 10 | + reset: () => void; |
| 11 | +}) { |
| 12 | + useEffect(() => { |
| 13 | + console.error('Application error:', error); |
| 14 | + }, [error]); |
| 15 | + |
| 16 | + return ( |
| 17 | + <div className="flex min-h-screen items-center justify-center bg-gray-50 px-4"> |
| 18 | + <div className="mx-auto w-full max-w-lg text-center"> |
| 19 | + <div className="mb-8"> |
| 20 | + <div className="mx-auto mb-4 flex h-20 w-20 items-center justify-center rounded-full bg-red-100"> |
| 21 | + <svg |
| 22 | + className="h-10 w-10 text-red-600" |
| 23 | + fill="none" |
| 24 | + stroke="currentColor" |
| 25 | + viewBox="0 0 24 24" |
| 26 | + > |
| 27 | + <path |
| 28 | + strokeLinecap="round" |
| 29 | + strokeLinejoin="round" |
| 30 | + strokeWidth={2} |
| 31 | + d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" |
| 32 | + /> |
| 33 | + </svg> |
| 34 | + </div> |
| 35 | + |
| 36 | + <h1 className="mb-3 text-3xl font-semibold text-gray-900">Oops! Something went wrong</h1> |
| 37 | + |
| 38 | + <p className="text-foreground-muted mb-8 text-lg"> |
| 39 | + We encountered an error while loading this page. Don't worry, it's not your fault. |
| 40 | + </p> |
| 41 | + </div> |
| 42 | + |
| 43 | + <div className="space-y-4"> |
| 44 | + <button |
| 45 | + onClick={() => reset()} |
| 46 | + className="bg-relisten-600 w-full rounded-lg px-6 py-3 font-medium text-white transition-colors hover:bg-relisten-700 sm:w-auto" |
| 47 | + > |
| 48 | + Try again |
| 49 | + </button> |
| 50 | + |
| 51 | + <div className="flex flex-col justify-center gap-3 sm:flex-row"> |
| 52 | + <button |
| 53 | + onClick={() => window.history.back()} |
| 54 | + className="rounded-lg bg-gray-100 px-6 py-3 text-gray-900 transition-colors hover:bg-gray-200" |
| 55 | + > |
| 56 | + Go back |
| 57 | + </button> |
| 58 | + |
| 59 | + <button |
| 60 | + onClick={() => (window.location.href = '/')} |
| 61 | + className="rounded-lg bg-gray-100 px-6 py-3 text-gray-900 transition-colors hover:bg-gray-200" |
| 62 | + > |
| 63 | + Go to homepage |
| 64 | + </button> |
| 65 | + </div> |
| 66 | + </div> |
| 67 | + |
| 68 | + {process.env.NODE_ENV === 'development' && ( |
| 69 | + <details className="mt-8 rounded-lg border border-gray-200 bg-white p-4 text-left"> |
| 70 | + <summary className="mb-3 cursor-pointer text-sm font-medium text-gray-700 hover:text-gray-900"> |
| 71 | + 🐛 Developer Info |
| 72 | + </summary> |
| 73 | + <div className="space-y-2"> |
| 74 | + <div> |
| 75 | + <span className="text-xs font-semibold tracking-wide text-gray-500 uppercase"> |
| 76 | + Error Message: |
| 77 | + </span> |
| 78 | + <p className="mt-1 rounded bg-red-50 p-2 font-mono text-sm text-red-700"> |
| 79 | + {error.message} |
| 80 | + </p> |
| 81 | + </div> |
| 82 | + {error.digest && ( |
| 83 | + <div> |
| 84 | + <span className="text-xs font-semibold tracking-wide text-gray-500 uppercase"> |
| 85 | + Error Digest: |
| 86 | + </span> |
| 87 | + <p className="mt-1 rounded bg-gray-50 p-2 font-mono text-sm text-gray-700"> |
| 88 | + {error.digest} |
| 89 | + </p> |
| 90 | + </div> |
| 91 | + )} |
| 92 | + {error.stack && ( |
| 93 | + <div> |
| 94 | + <span className="text-xs font-semibold tracking-wide text-gray-500 uppercase"> |
| 95 | + Stack Trace: |
| 96 | + </span> |
| 97 | + <pre className="mt-1 max-h-40 overflow-auto rounded bg-gray-50 p-3 text-xs text-gray-700"> |
| 98 | + {error.stack} |
| 99 | + </pre> |
| 100 | + </div> |
| 101 | + )} |
| 102 | + </div> |
| 103 | + </details> |
| 104 | + )} |
| 105 | + </div> |
| 106 | + </div> |
| 107 | + ); |
| 108 | +} |
0 commit comments