mirror of
https://github.com/BreizhHardware/express-prom-bundle.git
synced 2026-03-18 21:30:38 +01:00
Make normalizeStatusCode generic
This commit is contained in:
@@ -118,7 +118,7 @@ function main(opts) {
|
||||
let timer = metrics[httpMtricName].startTimer(labels);
|
||||
onFinished(res, () => {
|
||||
if (opts.normalizeStatusCode) {
|
||||
labels.status_code = main.normalizeStatusCode(req, opts);
|
||||
labels.status_code = main.normalizeStatusCode(res, opts);
|
||||
} else {
|
||||
labels.status_code = res.statusCode;
|
||||
}
|
||||
|
||||
@@ -1,22 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function(req, opts) {
|
||||
module.exports = function(res, opts) {
|
||||
opts = opts || {};
|
||||
|
||||
if (opts.formatStatusCode !== undefined && !opts.formatStatusCode) {
|
||||
return req.status_code;
|
||||
}
|
||||
if (typeof opts.formatStatusCode === 'function') {
|
||||
return opts.formatStatusCode(req, opts);
|
||||
return opts.formatStatusCode(res, opts);
|
||||
}
|
||||
|
||||
// Group Status code in 1xx, 2xx, 3xx, 4xx, 5xx or other
|
||||
const status_code = ({
|
||||
'1': '1xx',
|
||||
'2': '2xx',
|
||||
'3': '3xx',
|
||||
'4': '4xx',
|
||||
'5': '5xx',
|
||||
})[(req.status_code || '').substr(0,1)] || 'other';
|
||||
return status_code;
|
||||
return req.status_code;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user