From the course: Learning Koa

Unlock the full course today

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

Throw errors with context

Throw errors with context

From the course: Learning Koa

Start my 1-month free trial

Throw errors with context

- [Instructor] When we do transactions in the server, not all transactions will go successfully. And when it happens, we need to throw some errors to make sure the user, or the people developing the application, know what's happening. And the context offers a very simple way to throw errors when this happens. Let me demonstrate. So let's go back to VS code and the first thing we're going to do is probably erase all of this here except the response that we had initially here. So remove the console log here, remove the line 18, so let me just grab it from the top here and then just remove everything else. And I'm going to remove the explorer so I got more room to play. So the first thing we're going to do is insert an F statement inside of our app dot use. So I'm going to do F CTX dot user data so if we have some data in this guy here, then do this, return, and then we'll use that code here. So let's cut that and then paste it here. And what I'm going to do is, instead of just doing it…

Contents