In this video, explore the basics of error handling middleware in Express and how to customize the default error handler.
- [Instructor] So now comes the time…to handle errors in our APIs.…How do you go about it,…and what middleware is available in Express?…The beauty of Express is that there is…a default error handler built into your code…without a single line of code.…So let's go inside of VS Code,…go inside of index.js,…and in the get,…so let's scroll all the way up to the item ID,…or actually let's go to the item instead.…
So let's go here to the app.route item on line 48,…and what we'll do is basically…throw an error instead of sending it this thing here.…So let's go and throw an error,…and the way you do this is by…doing throw new Error,…and that is a function,…and that will automatically throw an error for us.…So basically we're simulating or we're forcing…an error to happen on this particular route…when we're getting it,…and what we'll do, we'll do that in the browser.…
So let's save this,…and let's go back to our browser,…and let's go to item like so,…and return that.…So as you can see, when we throw an error…or when there's an error occurring…
- Creating a basic data endpoint
- Routing with Express
- Adding a static route for file serving
- Basic middleware with Express
- Built-in middleware and error-handling middleware
- Debugging in an Express application
- Security best practices with Express
Skill Level Beginner
1. Setting Up Express
2. Getting Started
3. Routing with Express
4. Middleware with Express
5. Advanced Topics in Express
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.