Created
July 17, 2016 16:09
-
-
Save oxyno-zeta/a60aa7b0ef4a894482ef41e55681eeca to your computer and use it in GitHub Desktop.
NodeJS Get all codes in objects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const http = require('http'); | |
const _ = require('lodash'); | |
const INFORMATIONAL = {}; | |
const SUCCESS = {}; | |
const REDIRECTION = {}; | |
const CLIENT_ERROR = {}; | |
const SERVER_ERROR = {}; | |
_.forEach(http.STATUS_CODES, function (value, code) { | |
let key = value.replace(new RegExp(' ', 'g'), '_').replace(new RegExp('-', 'g'), '_').toUpperCase(); | |
let obj = { | |
code: code, | |
reason: value | |
}; | |
if (code >= 100 && code < 200) { | |
INFORMATIONAL[key] = obj; | |
} | |
else if (code >= 200 && code < 300) { | |
SUCCESS[key] = obj; | |
} | |
else if (code >= 300 && code < 400) { | |
REDIRECTION[key] = obj; | |
} | |
else if (code >= 400 && code < 500) { | |
CLIENT_ERROR[key] = obj; | |
} | |
else { | |
SERVER_ERROR[key] = obj; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment