Issue #7: Centralize Error Handling
Overview
Create a unified error handling system that works across all API calls, replacing the scattered error handlers with a clean, maintainable solution.
Your Task
Implement a centralized error handling system that eliminates error handling duplication and provides consistent error management throughout the application.
Specific Requirements
-
Create Error Handling Utilities
ErrorHandler class or object with methods for different error types
logError(error, context) - consistent error logging
displayUserError(error, sectionId) - user-friendly error display
isRetryableError(error) - determine if errors can be retried
-
Implement Error Categories
- Network errors (connection failed, timeout)
- HTTP errors (404, 500, etc.)
- Application errors (API returned error message)
- Validation errors (invalid parameters)
- Create appropriate handling for each category
-
Replace Scattered Error Handlers
- Remove all individual
onerror and error checking code
- Implement a single error handling flow
- Use try/catch blocks or Promise .catch() for centralized handling
- Maintain the same error display functionality in each section
-
Add Error Recovery Features
- Automatic retry logic for network errors (up to 3 attempts)
- Graceful degradation (show partial results when possible)
- User notification with retry buttons for failed sections
- Clear error messages explaining what went wrong
-
Improve User Experience
- Show specific error messages instead of generic "unavailable" text
- Add retry buttons to individual failed sections
- Implement progressive enhancement (show successful sections even if others fail)
- Add error state styling to failed sections
-
Error Logging and Monitoring
- Console logging with error context (which API call, what parameters)
- Error categorization for monitoring
- User action tracking (which errors do users encounter most?)
- Debug information for development vs. user-friendly messages for production
-
Configuration and Customization
- Configurable retry counts and delays
- Customizable error messages
- Different error handling strategies for different error types
- Easy way to add new error types without modifying existing code
Code Style Requirements
- Follow classroom standards (let vs var, if/else vs ternary, string concatenation)
- Use arrow functions for error handlers
- Add comprehensive comments
- Create reusable functions that can be easily tested
Expected Outcomes
- Reduce error handling code from ~20 lines to ~5 lines
- Eliminate code duplication across error handlers
- Provide better user experience with retry capabilities
- Make error handling easy to modify and extend
Testing Requirements
- Test each error type (network, HTTP, application)
- Verify retry logic works correctly
- Test partial failure scenarios
- Ensure error messages are user-friendly
Learning Goals
- Understand the benefits of centralized error handling
- Practice creating reusable error management systems
- Experience how proper error handling improves user experience
- Learn to design systems that are easy to test and modify
Issue #7: Centralize Error Handling
Overview
Create a unified error handling system that works across all API calls, replacing the scattered error handlers with a clean, maintainable solution.
Your Task
Implement a centralized error handling system that eliminates error handling duplication and provides consistent error management throughout the application.
Specific Requirements
Create Error Handling Utilities
ErrorHandlerclass or object with methods for different error typeslogError(error, context)- consistent error loggingdisplayUserError(error, sectionId)- user-friendly error displayisRetryableError(error)- determine if errors can be retriedImplement Error Categories
Replace Scattered Error Handlers
onerrorand error checking codeAdd Error Recovery Features
Improve User Experience
Error Logging and Monitoring
Configuration and Customization
Code Style Requirements
Expected Outcomes
Testing Requirements
Learning Goals