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,004 Points

error is not defined error

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

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

the app says that 'error' is not defined i don't know what's the problem

1 Answer

Steven Parker
Steven Parker
231,072 Points

It's not clear what course and lesson you are referring to, but one issue stand out in the code itself. The first function defines "error", but its scope is local to that function only.

The second function tries to reference it (res.locals.error = error), but it would not be defined at that point.