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.html
fix-express-errorhandling
Richard Hansen 2021-08-20 02:21:02 -04:00
parent 30e5bffaf2
commit 66a7cf73d8
2 changed files with 0 additions and 22 deletions

View File

@ -74,12 +74,6 @@
"expressCreateServer": "ep_etherpad-lite/node/hooks/express/importexport"
}
},
{
"name": "errorhandling",
"hooks": {
"expressCreateServer": "ep_etherpad-lite/node/hooks/express/errorhandling"
}
},
{
"name": "socketio",
"hooks": {

View File

@ -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();
};