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:
2025-12-01 21:18:57 +00:00
parent e51e88fddd
commit 12ce70e495
9 changed files with 796 additions and 225 deletions

View File

@@ -4,6 +4,22 @@ const globalForPrisma = globalThis as unknown as {
prisma: PrismaClient | undefined
}
export const prisma = globalForPrisma.prisma ?? new PrismaClient()
// Create Prisma client with connection error handling
export const prisma = globalForPrisma.prisma ?? new PrismaClient({
log: process.env.NODE_ENV === 'development' ? ['error', 'warn'] : ['error'],
})
// Handle connection errors
prisma.$connect().catch((error) => {
console.error('Failed to connect to database:', error)
// Don't throw here - let individual queries handle connection errors
})
// Graceful shutdown
if (typeof window === 'undefined') {
process.on('beforeExit', async () => {
await prisma.$disconnect()
})
}
if (process.env.NODE_ENV !== 'production') globalForPrisma.prisma = prisma