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

jason limmm
jason limmm
8,009 Points

error code not displaying in error page

here is my code, i can't seem to figure out why my error code is not displaying in the erorr page.

app.use((req, res, next)=>{
    const error = new Error('uh no!!!! no money for us!!!');
    res.status(error.status);
    next(err);
});

app.use((err, req, res, next)=>{
    res.locals.error = error;
    res.render('error');
});
extends layout

block content
    h1 wa uh oh!!! no meny for us :(
    h2 i hate errors too, i also like moeny too you know....
    h3= error.status

1 Answer

Rohald van Merode
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Rohald van Merode
Treehouse Staff

Hey jason limmm 👋

You'll want to have a look at that first route where you're creating the error. You're storing it in the variable error but are then passing err to next, which is undefined. You may want to try and pass the error instead 🙂

Hope this helps