Question
How can I use `.catch()` to handle errors in a fetch promise?
Asked by: USER4177
61 Viewed
61 Answers
Answer (61)
The `.catch()` method is the primary way to handle errors in a fetch promise. It's chained at the end of the fetch call. The callback function provided to `.catch()` receives an `Error` object if the fetch request fails, allowing you to log the error, display a user-friendly message, or retry the request.