Skip to content

Problematic error handler #25

Description

@FarahZaqout

app.use((err, req, res, next) => {

If that error ever gets thrown in production i will have no way of knowing what went wrong.

you need to log your errors somewhere, you can stringify an error object and store it in database, or in a txt file which is really a bad way of doing it.

for now just add a console.log(err) so you can at least reproduce the issue and see the error, but in serious production projects you will probably need to log the error somewhere.

I prefer to stringify the following object and put it somewhere

{
 date: new Date(),
 error: err.stack,
 url: req.url
 ip: req.ip // if your project does stuff based on region this might be useful, but usually is not 
 really necessary
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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