Skip to content

Bug Fix - Add Proper Error Handling for API Calls #4

@anna-dahlberg

Description

@anna-dahlberg

Description

The current code doesn't handle cases where the API might be down, the network is unavailable, or the API returns an error. We should add proper error handling to show users a friendly message instead of breaking silently.

Acceptance Criteria

  • Catch network errors in both JavaScript files
  • Display user-friendly error messages
  • Handle API-specific errors (like invalid lucky numbers)
  • Log errors to console for debugging
  • Reset button state even if API call fails

Technical Details

Consider these error scenarios:

  • Network is offline
  • API returns 404 for invalid advice slip ID
  • API is temporarily unavailable
  • Malformed JSON response

Files to Modify

  • scripts/advice.js - Add try/catch and error handling
  • scripts/luckyNumberAdvice.js - Add try/catch and error handling

Resources/References

Estimated Difficulty: Beginner Friendly

Additional Notes

Great for learning error handling patterns in JavaScript. Start with simple console.log statements and alert messages!

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions