stats: Move `http500` metric middleware to the beginning

fix-express-errorhandling
Richard Hansen 2021-08-20 02:35:56 -04:00
parent f08a443497
commit 1434129a7b
2 changed files with 7 additions and 3 deletions

View File

@ -112,6 +112,13 @@ exports.restartServer = async () => {
exports.server = http.createServer(app);
}
// This error-handling middleware is installed first to ensure that no other middleware can
// prevent the stats from being updated.
app.use((err, req, res, next) => {
stats.meter('http500').mark();
next(err);
});
app.use((req, res, next) => {
// res.header("X-Frame-Options", "deny"); // breaks embedded pads
if (settings.ssl) {

View File

@ -1,7 +1,5 @@
'use strict';
const stats = require('../../stats');
exports.expressCreateServer = (hook_name, args, cb) => {
exports.app = args.app;
@ -12,7 +10,6 @@ exports.expressCreateServer = (hook_name, args, cb) => {
// allowing you to respond however you like
res.status(500).send({error: 'Sorry, something bad happened!'});
console.error(err.stack ? err.stack : err.toString());
stats.meter('http500').mark();
});
return cb();