diff --git a/src/node/hooks/express.js b/src/node/hooks/express.js index 351ab5bf2..c16374b0c 100644 --- a/src/node/hooks/express.js +++ b/src/node/hooks/express.js @@ -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) { diff --git a/src/node/hooks/express/errorhandling.js b/src/node/hooks/express/errorhandling.js index 884ca9be0..b395f4606 100644 --- a/src/node/hooks/express/errorhandling.js +++ b/src/node/hooks/express/errorhandling.js @@ -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();