|
| 1 | +'use client'; |
| 2 | + |
| 3 | +import {useEffect} from 'react'; |
| 4 | +import {useParams} from 'next/navigation'; |
| 5 | +import {Inter} from 'next/font/google'; |
| 6 | +import clsx from 'clsx'; |
| 7 | +import Logo from 'public/assets/logo.svg'; |
| 8 | + |
| 9 | +const inter = Inter({subsets: ['latin']}); |
| 10 | + |
| 11 | +// Client-side translations fallback |
| 12 | +const translations = { |
| 13 | + en: { |
| 14 | + serverError: 'Something Went Wrong', |
| 15 | + serverErrorDesc: 'An unexpected error occurred. Please try again later.', |
| 16 | + goHome: 'Go Home', |
| 17 | + tryAgain: 'Try Again', |
| 18 | + }, |
| 19 | + ko: { |
| 20 | + serverError: '오류가 발생했습니다', |
| 21 | + serverErrorDesc: '예기치 않은 오류가 발생했습니다. 잠시 후 다시 시도해주세요.', |
| 22 | + goHome: '홈으로', |
| 23 | + tryAgain: '다시 시도', |
| 24 | + }, |
| 25 | +}; |
| 26 | + |
| 27 | +export default function Error({ |
| 28 | + error, |
| 29 | + reset, |
| 30 | +}: { |
| 31 | + error: Error & {digest?: string}; |
| 32 | + reset: () => void; |
| 33 | +}) { |
| 34 | + const params = useParams(); |
| 35 | + const lang = (params?.lang as 'en' | 'ko') || 'en'; |
| 36 | + const t = translations[lang]; |
| 37 | + |
| 38 | + useEffect(() => { |
| 39 | + console.error('Error:', error); |
| 40 | + }, [error]); |
| 41 | + |
| 42 | + return ( |
| 43 | + <div |
| 44 | + className={clsx( |
| 45 | + 'flex-1 w-full overflow-hidden', |
| 46 | + 'flex flex-col justify-center items-center', |
| 47 | + 'px-4', |
| 48 | + )} |
| 49 | + > |
| 50 | + <div |
| 51 | + className={clsx( |
| 52 | + 'bg-modal max-w-[480px] w-full rounded-2xl px-12 py-16', |
| 53 | + 'flex flex-col items-center justify-center', |
| 54 | + )} |
| 55 | + > |
| 56 | + <Logo className="w-20 h-20 mb-2 text-brand" /> |
| 57 | + <p className={clsx('text-brand pb-8', inter.className)}>github-stats</p> |
| 58 | + |
| 59 | + <h1 |
| 60 | + className={clsx( |
| 61 | + 'text-9xl font-bold text-contrast mb-4', |
| 62 | + inter.className, |
| 63 | + )} |
| 64 | + > |
| 65 | + 500 |
| 66 | + </h1> |
| 67 | + <h2 |
| 68 | + className={clsx( |
| 69 | + 'text-3xl font-semibold text-contrast mb-4', |
| 70 | + inter.className, |
| 71 | + )} |
| 72 | + > |
| 73 | + {t.serverError} |
| 74 | + </h2> |
| 75 | + <p |
| 76 | + className={clsx( |
| 77 | + 'text-placeholder text-center mb-8 max-w-md', |
| 78 | + inter.className, |
| 79 | + )} |
| 80 | + > |
| 81 | + {t.serverErrorDesc} |
| 82 | + </p> |
| 83 | + |
| 84 | + <div className="flex gap-4 justify-center"> |
| 85 | + <button |
| 86 | + onClick={reset} |
| 87 | + className={clsx( |
| 88 | + 'px-8 py-3 rounded-lg', |
| 89 | + 'bg-border hover:opacity-80', |
| 90 | + 'text-contrast font-medium', |
| 91 | + 'transition-all duration-200', |
| 92 | + inter.className, |
| 93 | + )} |
| 94 | + > |
| 95 | + {t.tryAgain} |
| 96 | + </button> |
| 97 | + <a |
| 98 | + href={`/${lang}`} |
| 99 | + className={clsx( |
| 100 | + 'inline-block px-8 py-3 rounded-lg', |
| 101 | + 'bg-btn-primary hover:opacity-80', |
| 102 | + 'text-btn-primary-text font-medium', |
| 103 | + 'transition-all duration-200', |
| 104 | + inter.className, |
| 105 | + )} |
| 106 | + > |
| 107 | + {t.goHome} |
| 108 | + </a> |
| 109 | + </div> |
| 110 | + </div> |
| 111 | + </div> |
| 112 | + ); |
| 113 | +} |
0 commit comments