Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error handler doesn't work if I remove next parameter #3715

Closed
frederikhors opened this issue Aug 13, 2018 · 6 comments
Closed

error handler doesn't work if I remove next parameter #3715

frederikhors opened this issue Aug 13, 2018 · 6 comments

Comments

@frederikhors
Copy link

I'm learning Express.js and using the generator I generated a new app with:

npm install express-generator -g && express myapp

After that I saw in app.js that there is this code:

    // catch 404 and forward to error handler
    app.use(function(req, res, next) {
      next(createError(404));
    });
    
    // error handler
    app.use(function(err, req, res, next) {
      // set locals, only providing error in development
      res.locals.message = err.message;
      res.locals.error = req.app.get("env") === "development" ? err : {};
    
      // render the error page
      res.status(err.status || 500);
      res.render("error");
    });

enter image description here

As you can see in the image eslint is complaining about next parameter, declared and never used. I agree, but if I remove it express doesn't render the error page.

Why this behavior?

This is dangerous for me because I can't trust anymore eslint or my coding degree? I'm surely missing something. But what?

@dougwilson
Copy link
Contributor

This is correct behavior. You may need to configure your eslint to work better with Express.js code. We recommend StandardJS or one of it's derritives.

You can read more about how error handling works in Express and why the next argument is important here: http://expressjs.com/en/guide/error-handling.html

@niftylettuce
Copy link

@frederikhors you can add this line right above the line with the next argument - // eslint-disable-next-line no-unused-vars

@frederikhors
Copy link
Author

@niftylettuce thanks. I dropped out eslint for StandardJS.

@frederikhors
Copy link
Author

@niftylettuce but still I think something is not elegant in this way...

@LinusU
Copy link
Member

LinusU commented Aug 14, 2018

Yeah, I agree on it not being super elegant, and would personally like to see it changed in 5.x, there is an open issue about this here: #2896

@wesleytodd
Copy link
Member

wesleytodd commented Aug 14, 2018

Also I have a proposed fix for this in this comment: pillarjs/router#59 (comment)

If anyone has feedback I would appreciate it. I am willing to put together the final PR for that if people are happy with the approach, but I have been waiting on feedback to that post.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants