Join egghead, unlock knowledge.

Want more egghead?

This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock This Lesson
1×
Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.

Autoplay

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

    javascriptJavaScript

    The Promise.prototype.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() method: .catch(onRejected) behaves the same as .then(undefined, onRejected).