Skip to content

Instantly share code, notes, and snippets.

@axetroy
Created November 27, 2017 10:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save axetroy/03ecdff2a5cf5c89c9324ea24986f05c to your computer and use it in GitHub Desktop.
Save axetroy/03ecdff2a5cf5c89c9324ea24986f05c to your computer and use it in GitHub Desktop.
Http status code and message module
/**
* Generate a New status
* @param code
* @param message
* @constructor
*/
function Status(code, message) {
this.code = code;
this.message = message;
}
Status.prototype.valueOf = function() {
return this.code;
};
Status.prototype.toString = function() {
return this.message;
};
function define(key, code, message) {
Object.defineProperty(hs, key, {
configurable: false,
enumerable: true,
get() {
return new Status(code, message);
}
});
}
define('Continue', 100, 'Continue');
define('SwitchingProtocols', 101, 'Switching Protocols');
define('Processing', 102, 'Processing');
define('OK', 200, 'OK');
define('Created', 201, 'OK');
define('Accepted', 202, 'OK');
define('NonAuthoritativeInfo', 203, 'OK');
define('NoContent', 204, 'OK');
define('ResetContent', 205, 'OK');
define('PartialContent', 206, 'OK');
define('MultiStatus', 207, 'OK');
define('AlreadyReported', 208, 'OK');
define('IMUsed', 226, 'OK');
// 100
hs.Continue = new Status(100, 'Continue');
hs.SwitchingProtocols = new Status(101, 'Switching Protocols');
hs.Processing = new Status(102, 'Processing');
// 200
hs.OK = new Status(200, 'OK');
hs.Created = new Status(201, 'Continue');
hs.Accepted = new Status(202, 'Continue');
hs.NonAuthoritativeInfo = new Status(203, 'Continue');
hs.NoContent = new Status(204, 'Continue');
hs.ResetContent = new Status(205, 'Continue');
module.exports = hs;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment