Overview
Mizen implements a robust error handling system that provides:- Structured error responses across all API endpoints
- User-friendly error messages with actionable guidance
- Client-side error logging for debugging
- Consistent error codes for programmatic handling
- Retry functionality with rate limit support
Error Response Structure
All API routes return a consistent response format:Success Response
Error Response
Error Codes
Standard Error Codes
Defined insrc/utils/formatError.ts:27
| Code | When It Occurs | User Message |
|---|---|---|
ERR_INVALID_URL | URL doesn’t pass validation | ”That doesn’t look like a valid URL” |
ERR_UNSUPPORTED_DOMAIN | Site not supported | ”We don’t support this website yet” |
ERR_FETCH_FAILED | Network or scraping fetch fails | ”We couldn’t reach that page” |
ERR_NO_RECIPE_FOUND | Scraper/AI returns no data | ”No recipe found on this page” |
ERR_AI_PARSE_FAILED | AI response is invalid | ”We found the page but couldn’t extract the recipe” |
ERR_TIMEOUT | Long response time or crash | ”That website is taking too long” |
ERR_RATE_LIMIT | Too many requests | ”Too many requests” |
ERR_API_UNAVAILABLE | AI service down | ”Our service is temporarily down” |
ERR_UNKNOWN | Catch-all for uncaught errors | ”Something went wrong” |
ERR_INVALID_FILE_TYPE | Wrong image format | ”Please select a valid image file” |
ERR_FILE_TOO_LARGE | Image exceeds 10MB | ”Image size must be less than 10MB” |
ERR_NOT_A_URL | Input is not a URL | ”Paste a recipe URL” |
ERR_FEEDBACK_SUBMIT_FAILED | Feedback submission fails | ”Failed to submit feedback” |
ERR_FEEDBACK_UPLOAD_FAILED | Screenshot upload fails | ”Failed to upload screenshots” |
Code Constants
Enhanced Error Details
Error Information Structure
Example: Invalid URL Error
Example: Fetch Failed Error
Backend Error Handling
API Route Error Handling Pattern
Example from/api/parseRecipe (src/app/api/parseRecipe/route.ts:49)
Error Categorization Logic
Fromsrc/app/api/parseRecipe/route.ts:82
Client-Side Error Handling
Error Handler Hook
Location:src/hooks/useRecipeErrorHandler.ts
Usage in Components
Error Logging System
Client-Side Error Logger
Location:src/utils/errorLogger.ts
Error Log Features
- Automatic rotation — Keeps only last 50 errors to prevent localStorage bloat
- Structured data — Timestamp, code, message, URL, user agent
- Console integration — Also logs to browser console for immediate debugging
- Export functionality — Export logs as JSON for sharing with team
- Persistent storage — Survives page refreshes and browser sessions
Accessing Error Logs
In browser console:Rate Limiting
Rate Limit Error Response
Client-Side Rate Limit Handling
Error Display Component
Visual Error Display
From TECHNICAL_SUMMARY.md:Accessibility Features
- ARIA labels — Proper
role="alert"andaria-live="assertive" - Keyboard navigation — All buttons/links keyboard accessible
- Screen reader support — Error messages announced to screen readers
- Visual feedback — Red theme, clear error icons
Error Prevention
Input Validation
URL Validation (src/app/api/urlValidator/route.ts):
Timeout Handling
API Request Timeouts:Error Recovery
Retry Functionality
User-Initiated Retry:Graceful Degradation
Fallback Strategies:- JSON-LD fails → Try AI parsing
- AI parsing fails → Try Python scraper (legacy)
- All parsing fails → Show error with “Visit Page” option
- Image extraction fails → Continue without images
- Substitutions fail → Recipe still usable without them
Debugging Error Handling
Console Logging
Server-side (API routes):Error Log Analysis
Viewing error patterns:Testing Error Handling
Test Error Scenarios
- Invalid URLs — Test various malformed URLs
- Unsupported sites — Sites without JSON-LD or recipe content
- Network failures — Simulate offline/slow connections
- AI service outages — Test when Groq API is down
- Rate limiting — Test behavior when rate limited
- Timeout scenarios — Very slow-loading pages
- Malformed responses — Invalid JSON from AI
- Large files — Images exceeding 10MB
Manual Testing
Test invalid URLs:Future Improvements
From TECHNICAL_SUMMARY.md:- Sentry integration — Real-time error tracking in production
- Error analytics — Track error frequency and user impact
- Automatic retries — Retry transient errors automatically
- Better error messages — Context-aware suggestions
- Error reporting UI — Allow users to report errors with screenshots
- Performance monitoring — Track API response times and failures