Skip to content

Commit

Permalink
refactor: use subset of http-status (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
snyamathi committed Jul 26, 2021
1 parent f34f8d7 commit 5b09a0e
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 8 deletions.
2 changes: 1 addition & 1 deletion HttpError.js
Expand Up @@ -5,7 +5,7 @@

'use strict';

var STATUS_CODES = require('http-status');
var STATUS_CODES = require('./libs/http-status');
var DEFAULT_STATUS_CODE = 500;

function HttpError (status, message, options) {
Expand Down
2 changes: 1 addition & 1 deletion libs/helper.js
Expand Up @@ -5,7 +5,7 @@

'use strict';

var STATUS_CODES = require('http-status');
var STATUS_CODES = require('./http-status');
var camelCase = require('camelcase');

module.exports = {
Expand Down
64 changes: 64 additions & 0 deletions libs/http-status.js
@@ -0,0 +1,64 @@
module.exports = {
100: 'Continue',
101: 'Switching Protocols',
102: 'Processing',
103: 'Early Hints',
200: 'OK',
201: 'Created',
202: 'Accepted',
203: 'Non-Authoritative Information',
204: 'No Content',
205: 'Reset Content',
206: 'Partial Content',
207: 'Multi Status',
208: 'Already Reported',
226: 'IM Used',
300: 'Multiple Choices',
301: 'Moved Permanently',
302: 'Found',
303: 'See Other',
304: 'Not Modified',
305: 'Use Proxy',
306: 'Switch Proxy',
307: 'Temporary Redirect',
308: 'Permanent Redirect',
400: 'Bad Request',
401: 'Unauthorized',
402: 'Payment Required',
403: 'Forbidden',
404: 'Not Found',
405: 'Method Not Allowed',
406: 'Not Acceptable',
407: 'Proxy Authentication Required',
408: 'Request Time-out',
409: 'Conflict',
410: 'Gone',
411: 'Length Required',
412: 'Precondition Failed',
413: 'Request Entity Too Large',
414: 'Request-URI Too Large',
415: 'Unsupported Media Type',
416: 'Requested Range not Satisfiable',
417: 'Expectation Failed',
418: 'I\'m a teapot',
421: 'Misdirected Request',
422: 'Unprocessable Entity',
423: 'Locked',
424: 'Failed Dependency',
426: 'Upgrade Required',
428: 'Precondition Required',
429: 'Too Many Requests',
431: 'Request Header Fields Too Large',
451: 'Unavailable For Legal Reasons',
500: 'Internal Server Error',
501: 'Not Implemented',
502: 'Bad Gateway',
503: 'Service Unavailable',
504: 'Gateway Time-out',
505: 'HTTP Version not Supported',
506: 'Variant Also Negotiates',
507: 'Insufficient Storage',
508: 'Loop Detected',
510: 'Not Extended',
511: 'Network Authentication Required'
}
3 changes: 1 addition & 2 deletions package.json
Expand Up @@ -16,8 +16,7 @@
"test": "npm run lint && npm run cover"
},
"dependencies": {
"camelcase": "^3.0.0",
"http-status": "^1.4.2"
"camelcase": "^3.0.0"
},
"devDependencies": {
"chai": "^4.2.0",
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/HttpError.js
Expand Up @@ -5,7 +5,7 @@
var ROOT_DIR = require('path').resolve(__dirname, '../..');

var expect = require('chai').expect;
var STATUS_CODES = require('http-status');
var STATUS_CODES = require(ROOT_DIR + '/libs/http-status');

describe('HttpError', function () {
var HttpError;
Expand All @@ -14,7 +14,7 @@ describe('HttpError', function () {
HttpError = require(ROOT_DIR + '/HttpError');
});

it('shoudl have a #name', function () {
it('should have a #name', function () {
expect(HttpError).to.have.property('name', 'HttpError');
});

Expand All @@ -38,7 +38,7 @@ describe('HttpError', function () {
expect(error).to.have.property('message', defaultError.message);
});

it('should set the proper error messge for the passed in status', function () {
it('should set the proper error message for the passed in status', function () {
var error = new HttpError(400);
expect(error).to.be.an('object').and.have.property('statusCode', 400);
expect(error).to.have.property('message', STATUS_CODES[400]);
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/libs/fumble.http.js
Expand Up @@ -6,7 +6,7 @@ var ROOT_DIR = require('path').resolve(__dirname, '../../..');

var expect = require('chai').expect;

var HTTP_STATUS_CODES = require('http-status');
var HTTP_STATUS_CODES = require(ROOT_DIR + '/libs/http-status');
var HttpError = require(ROOT_DIR + '/HttpError');
var config = require(ROOT_DIR + '/config').http;

Expand Down

0 comments on commit 5b09a0e

Please sign in to comment.