Menu Close

JS How to handle promise rejections

Promises are one of the best things that happened to JavaScript in the past few years.When we invoke a function that returns a promise, we chain the then() method of the promise to run a function when the promise resolves.Here’s an example using the Fetch API:fetch(‘/data.json’) .then(response => { console.log(response.status) }) What if there is an error during the fetch() call? Perhaps the network is unavailable. Or the network request returns an error.

Source: How to handle promise rejections

Similar

Comments are welcome.