nzakas / understandinges6

Content for the ebook "Understanding ECMAScript 6"
5.45k stars 796 forks source link

Potential typo in 11 - Promises - Node.js Rejection Handling #455

Open ronen-e opened 3 years ago

ronen-e commented 3 years ago

Where Chapter 11 - Promises, under Node.js Rejection Handling

let rejected;

process.on("unhandledRejection", function(reason, promise) {
    console.log(reason.message);            // "Explosion!"
    console.log(rejected === promise);      // true
});

rejected = Promise.reject(new Error("Explosion!"));

Problem

This example creates a rejected promise with an error object and listens for the unhandledRejection event.

Reason It is not clear that the error object is the promise value

Solution

This example creates a rejected promise with an error object as its value and listens for the unhandledRejection event.