Skip to content

Latest commit

 

History

History
16 lines (10 loc) · 526 Bytes

how_to_catch_errors_in_promises.md

File metadata and controls

16 lines (10 loc) · 526 Bytes

How to catch errors in Promises

You can handle errors in promises by appending a .catch() method to the promise chain.

fetch('https://api.example.com/data')
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error('Error:', error));

Tags: beginner, JavaScript, Promises, Error Handling