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!'); });