Now there's a chance that things didn't go well. We have to handle errors inside our Node applications. In that case, we wouldn't call resolve, we would call reject. Let's comment out the resolve line, and create a second one, where we call reject. We'll call reject much the same way we called resolve. We have to pass in one argument, and in this case, a simple error message like Unable to fulfill promise will do:
var somePromise = new Promise((resolve, reject) => {
setTimeout(() => {
// resolve('Hey. It worked!');
reject('Unable to fulfill promise');
}, 2500);
});
Now when we call reject, we're telling the promise that it has been rejected. This means that the thing we tried to do did not go well. Currently, we don't have an argument that handles this. As we mentioned, this function only gets called when things go as expected, not when we have errors. If I save the file and rerun it in Terminal, what we'll get is a promise that rejects:

However, we don't have a handler for it, so nothing will print to the screen. This will be a pretty big problem. We need to do something with that error message. Maybe we will alert the user, or we will try some other code.
As shown in the previous code output, we can see that nothing printed between the restarting and exiting. In order to do something with the error, we'll add a second argument to the then method. This second argument is what lets us handle errors in our promises. This argument will get executed and called with that value. In this case, it's our message. We'll create an argument called errorMessage, as shown here:
somePromise.then((message) => {
console.log('Success: ', message);
}, (errorMessage) => {
});
Inside the argument, we can do something with that. In this case, we'll print it to the screen using console.log, printing Error with a colon and a space to add some nice formatting, followed by the actual value that was rejected:
}, (errorMessage) => {
console.log('Error: ', errorMessage);
});
Now that we have this in place, we can refresh things by saving the file. We will now see our error message in Terminal, because we now have a place for it to do something:

Here, we have a place for it to print the message to the screen; Unable to fulfill promise prints to the screen, which works exactly as expected.