node.js - Express js - Error handling in middleware -


i have route

 app.get("/some/url/", function(req, res){ res.sendstatus(404) }) 

i trying handle or catch 404 in express error handling middleware , not working

 app.use(function(err, req, res, next){do here}) 

any how capture error thrown route in middleware.

app.get("/some/url/", function(req, res) {      // generate error yourself.      throw new error("generated error.");  });    // global error handler  app.use(function(err, req, res, next) {      console.dir(err);          // error status code , message here.      res.status(500).send('something broke!');  });


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo