I want to save the amount of 4XX and 5XX errors served by my server. The approach that I took was to create an express middleware to get the statusCode response
const fooMiddleware = (req, res, next) => {
req.stats.totalRequestsServed += 1;
// I want to access the status code sent to the client here
console.log('status code', res.statusCode);
next(null);
};
I'm using the code above but I'm always getting a 200
status code, even If I hardcode a res.status(401).end()
on my route.