Skip to content

Issue #7: Centralize Error Handling #9

@PatrickFrankAIU

Description

@PatrickFrankAIU

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

  1. 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
  2. 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
  3. 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
  4. 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
  5. 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
  6. 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
  7. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    RefactoringRefactoring exercises to improve the code using more modern methods.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions