Catch Errors in a JavaScript Promise Chain with Promise.prototype.catch()


Dec 06 2018 6 mins  
The [`Promise.prototype.then()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then) method accepts two callbacks as parameters, `onFulfilled` and `onRejected`:

- If the promise is fulfilled, `onFulfilled` will be called.
- If the promise is rejected, `onRejected` will be called.
- If the promise never settles (that is, stays pending forever), neither one will be called.

If you want to register a handler for rejected promises only, you can use the [`Promise.prototype.catch()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch) method: `.catch(onRejected)` behaves the same as `.then(undefined, onRejected)`.