stats: Add metrics for all HTTP status codes

fix-express-errorhandling
Richard Hansen 2021-08-20 02:41:46 -04:00
parent 1434129a7b
commit 30e5bffaf2
1 changed files with 8 additions and 7 deletions

View File

@ -1,6 +1,7 @@
'use strict';
const _ = require('underscore');
const assert = require('assert').strict;
const cookieParser = require('cookie-parser');
const events = require('events');
const express = require('express');
@ -112,14 +113,14 @@ 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) => {
// This stats logic should be in the first middleware to ensure that no other middleware can
// prevent the stats from being updated.
res.on('finish', () => {
assert(res.statusCode);
stats.meter(`http${res.statusCode}`).mark();
});
// res.header("X-Frame-Options", "deny"); // breaks embedded pads
if (settings.ssl) {
// we use SSL