Make normalizeStatusCode generic

This commit is contained in:
Paulo Duarte
2017-03-24 02:18:41 -03:00
parent 61e4343a8c
commit 48f8b992fd
2 changed files with 4 additions and 12 deletions

View File

@@ -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;
};