You're building a weather application and you're using the Fetch API to request weather data from a third-party API. However, you realize that the application does not properly handle when the API is down. How would you handle this to inform the user?

  • Implement a try-catch block to catch network errors and display a user-friendly message.
  • Use the finally block to handle any errors and show an alert to the user.
  • Utilize the window.onerror event to detect API failures and log them.
  • Set up a timer to periodically check the API status and notify the user if it's down.
To handle API failures and inform the user, you should implement a try-catch block around the fetch request. This allows you to catch network errors, like when the API is down, and then display a user-friendly message or take appropriate action. The other options are not recommended for handling API failures effectively.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *