Skip to content

What is the purpose of calling next after handling the error? #34

@ajsaraujo

Description

@ajsaraujo

README.md proposes this handling function:

app.use((err, req, res, next) => {
  if (err.message === 'access denied') {
    res.status(403);
    res.json({ error: err.message });
  }
 
  next(err);
});

But what is the purpose of calling next(err) after the error is handled?

I based my handling function on that and I was having problems with it. Express was throwing the error again when I called next(error). After I removed it, the code worked just fine. I believe this might be the cause for the problem some people are reporting in #33.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions