Implements group in status code metrics

This commit is contained in:
Paulo Duarte
2017-03-23 14:11:49 -03:00
parent 7b89690d3b
commit 61e4343a8c
3 changed files with 30 additions and 2 deletions

View File

@@ -0,0 +1,22 @@
'use strict';
module.exports = function(req, opts) {
opts = opts || {};
if (opts.formatStatusCode !== undefined && !opts.formatStatusCode) {
return req.status_code;
}
if (typeof opts.formatStatusCode === 'function') {
return opts.formatStatusCode(req, 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;
};