Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript One Solution

Tyler McDonald
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Tyler McDonald
Full Stack JavaScript Techdegree Graduate 16,700 Points

Several questions about error handling in Express

I have watched various videos on treehouse and youtube, read documentation on express, and other tutorials. For some reason error handling is not clicking for me. I will try to be specific with some questions.

  1. Why do we need to name multiple 404 errors? In app.js there is an app.use() function that creates/handles(?) 404 errors. But then in quotes.js we also created a new Error() with 404 status. How this is all flowing through the program?

  2. In the app.js 404 error handler, why do we not need to call next(), and why do we not use the err parameter?

  3. In app.js in the global error handler, we set the error status like this: err.status(500), but in quotes.js in the router.get("/:id"), we set it like this: err.status = 404. What is the difference here?

  4. When do we need to manually call new Error(), vs relying on Express to handle the errors?

  5. In quotes.js, what is the point of the router.get('/error')? Was this just to get a point across, or is this something we would do in a production server for any reason?