Implement comprehensive error handling
- Add try-catch blocks to all server actions with retry logic - Implement exponential backoff retry mechanism for database operations - Add input validation to all server actions - Create ErrorBoundary component for React error handling - Add page-level error handlers (error.tsx, global-error.tsx) - Add route-specific error pages for list and item routes - Enhance database connection with graceful error handling - Add user-friendly error messages throughout the application - Implement proper error logging for debugging Task: 16. Implement error handling Requirements: All (error handling is cross-cutting)
This commit is contained in:
50
app/global-error.tsx
Normal file
50
app/global-error.tsx
Normal file
@@ -0,0 +1,50 @@
|
||||
'use client'
|
||||
|
||||
import { useEffect } from 'react'
|
||||
import { AlertTriangle } from 'lucide-react'
|
||||
|
||||
export default function GlobalError({
|
||||
error,
|
||||
reset,
|
||||
}: {
|
||||
error: Error & { digest?: string }
|
||||
reset: () => void
|
||||
}) {
|
||||
useEffect(() => {
|
||||
console.error('Global error:', error)
|
||||
}, [error])
|
||||
|
||||
return (
|
||||
<html lang="en">
|
||||
<body className="bg-gray-50 min-h-screen">
|
||||
<div className="min-h-screen flex items-center justify-center p-4">
|
||||
<div className="max-w-md w-full bg-white rounded-lg shadow-lg p-6 sm:p-8">
|
||||
<div className="flex items-center justify-center w-12 h-12 sm:w-16 sm:h-16 bg-red-100 rounded-full mx-auto mb-4">
|
||||
<AlertTriangle className="w-6 h-6 sm:w-8 sm:h-8 text-red-600" />
|
||||
</div>
|
||||
<h2 className="text-xl sm:text-2xl font-bold text-gray-900 text-center mb-2">
|
||||
Application Error
|
||||
</h2>
|
||||
<p className="text-sm sm:text-base text-gray-600 text-center mb-6">
|
||||
A critical error occurred. Please refresh the page or contact support if the problem persists.
|
||||
</p>
|
||||
<div className="flex flex-col sm:flex-row gap-3">
|
||||
<button
|
||||
onClick={reset}
|
||||
className="flex-1 px-4 py-3 bg-blue-500 hover:bg-blue-600 active:bg-blue-700 text-white rounded-lg transition-colors font-medium text-sm sm:text-base"
|
||||
>
|
||||
Try Again
|
||||
</button>
|
||||
<button
|
||||
onClick={() => window.location.href = '/'}
|
||||
className="flex-1 px-4 py-3 bg-gray-200 hover:bg-gray-300 active:bg-gray-400 text-gray-700 rounded-lg transition-colors font-medium text-sm sm:text-base"
|
||||
>
|
||||
Go Home
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user