Skip to content

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

Closed
@frederikhors

Description

@frederikhors

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions