Let Express log HTTP handler errors
Express already comes with a built-in error handler that is attached as the last middleware. Any handler or middleware can pass an Error object (with an optional `.status` or `.statusCode` property set to a 4xx or 5xx code) to `next()` and Express will both log a detailed error message and display a useful error message to the user. For more details see "The default error handler" at: https://expressjs.com/en/guide/error-handling.htmlfix-express-errorhandling
parent
30e5bffaf2
commit
66a7cf73d8
|
@ -74,12 +74,6 @@
|
||||||
"expressCreateServer": "ep_etherpad-lite/node/hooks/express/importexport"
|
"expressCreateServer": "ep_etherpad-lite/node/hooks/express/importexport"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"name": "errorhandling",
|
|
||||||
"hooks": {
|
|
||||||
"expressCreateServer": "ep_etherpad-lite/node/hooks/express/errorhandling"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"name": "socketio",
|
"name": "socketio",
|
||||||
"hooks": {
|
"hooks": {
|
||||||
|
|
|
@ -1,16 +0,0 @@
|
||||||
'use strict';
|
|
||||||
|
|
||||||
exports.expressCreateServer = (hook_name, args, cb) => {
|
|
||||||
exports.app = args.app;
|
|
||||||
|
|
||||||
// Handle errors
|
|
||||||
args.app.use((err, req, res, next) => {
|
|
||||||
// if an error occurs Connect will pass it down
|
|
||||||
// through these "error-handling" middleware
|
|
||||||
// allowing you to respond however you like
|
|
||||||
res.status(500).send({error: 'Sorry, something bad happened!'});
|
|
||||||
console.error(err.stack ? err.stack : err.toString());
|
|
||||||
});
|
|
||||||
|
|
||||||
return cb();
|
|
||||||
};
|
|
Loading…
Reference in New Issue