Join Daniel Khan for an in-depth discussion in this video Handling errors in Express, part of Building a Website with Node.js and Express.js.
- [Instructor] We've learned that in Express,…each middleware function can either…send a response which ends the request cycle…or call the next middleware in the chain using next.…We also saw that we can send…a HTTP status code like 400 to signal an error.…Handling errors in individual routes can get redundant…if there are various error conditioned.…And it's generally a good practice…to deal with errors in a more generic way.…Additionally to terminating the request…with an error code as we did before,…there're two more ways to create an error in Express.…
First we can throw an exception.…Let's try this out.…For that I will create a new route down here…and…I will…call it app.get.…And let's keep it simple and call it /throw.…The route again gets the request response…and the next object and their...…
In there I will throw an exception…by adding throw new Error.…And let's…say something is wrong.…Now let's start the web server, head over to the browser,…and let's call this route /throw.…You see that Express will send an error…
- Creating a server with Express and pure Node.js
- Handling errors in Express
- Creating routes
- Using templates
- Working with the Pug template engine
- Implementing the site structure and logic
- Working with conditionals
- Dealing with POST requests
- Sanitizing user inputs and handling form errors
Skill Level Beginner
What you should know1m 40s
1. Getting Started
2. Express Basics
3. Getting Started with Our Project
4. Getting Started with Templates
5. Implementing the Site Structure and Logic
6. Handling Form Data
- 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.