From the course: Advanced Node.js

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Rejecting promises

Rejecting promises - Node.js Tutorial

From the course: Advanced Node.js

Start my 1-month free trial

Rejecting promises

- [Instructor] In the last lesson, we introduced the Promise object and saw how it could be used to handle asynchronous code. What we didn't implement with this Promise object is what happens if something goes wrong. So within the Promise itself, we get to send it the code that it will invoke and anywhere this code can cause an error. I can actually throw a new error and we'll call this error ar. So let's just assume that an error happens anywhere within our Promise. That means when we come over here to run the code, I do note that, oh, we see an error. Well that makes sense because we threw an error. Let me go ahead and drag this out so we can see this full error here. What you'll notice is we see an unhandled Promise rejection, that means that an error has occurred within a Promise but we didn't handle it. If I look at this Promise that I invoked in the last lesson, we can see several then methods but there is nothing here to handle an error. Within Promises, we can handle the error…

Contents