[errors] ensure that error.status is always a number when defined
This commit is contained in:
@ -92,53 +92,54 @@ errors.RequestTypeError = function RequestTypeError(feature) {
|
||||
};
|
||||
_.inherits(errors.RequestTypeError, ErrorAbstract);
|
||||
|
||||
var statusCodes = {
|
||||
300: 'Multiple Choices',
|
||||
301: 'Moved Permanently',
|
||||
302: 'Found',
|
||||
303: 'See Other',
|
||||
304: 'Not Modified',
|
||||
305: 'Use Proxy',
|
||||
307: 'Temporary Redirect',
|
||||
308: 'Permanent Redirect',
|
||||
400: 'Bad Request',
|
||||
401: 'Authentication Exception',
|
||||
402: 'Payment Required',
|
||||
403: ['Authorization Exception', 'Forbidden'],
|
||||
404: 'Not Found',
|
||||
405: 'Method Not Allowed',
|
||||
406: 'Not Acceptable',
|
||||
407: 'Proxy Authentication Required',
|
||||
408: 'Request Timeout',
|
||||
409: 'Conflict',
|
||||
410: 'Gone',
|
||||
411: 'Length Required',
|
||||
412: 'Precondition Failed',
|
||||
413: 'Request Entity Too Large',
|
||||
414: 'Request URIToo Long',
|
||||
415: 'Unsupported Media Type',
|
||||
416: 'Requested Range Not Satisfiable',
|
||||
417: 'Expectation Failed',
|
||||
418: 'Im ATeapot',
|
||||
421: 'Too Many Connections From This IP',
|
||||
426: 'Upgrade Required',
|
||||
429: 'Too Many Requests',
|
||||
450: 'Blocked By Windows Parental Controls',
|
||||
494: 'Request Header Too Large',
|
||||
497: 'HTTPTo HTTPS',
|
||||
499: 'Client Closed Request',
|
||||
var statusCodes = [
|
||||
[ 300, 'Multiple Choices' ],
|
||||
[ 301, 'Moved Permanently' ],
|
||||
[ 302, 'Found' ],
|
||||
[ 303, 'See Other' ],
|
||||
[ 304, 'Not Modified' ],
|
||||
[ 305, 'Use Proxy' ],
|
||||
[ 307, 'Temporary Redirect' ],
|
||||
[ 308, 'Permanent Redirect' ],
|
||||
[ 400, 'Bad Request' ],
|
||||
[ 401, 'Authentication Exception' ],
|
||||
[ 402, 'Payment Required' ],
|
||||
[ 403, ['Authorization Exception', 'Forbidden'] ],
|
||||
[ 404, 'Not Found' ],
|
||||
[ 405, 'Method Not Allowed' ],
|
||||
[ 406, 'Not Acceptable' ],
|
||||
[ 407, 'Proxy Authentication Required' ],
|
||||
[ 408, 'Request Timeout' ],
|
||||
[ 409, 'Conflict' ],
|
||||
[ 410, 'Gone' ],
|
||||
[ 411, 'Length Required' ],
|
||||
[ 412, 'Precondition Failed' ],
|
||||
[ 413, 'Request Entity Too Large' ],
|
||||
[ 414, 'Request URIToo Long' ],
|
||||
[ 415, 'Unsupported Media Type' ],
|
||||
[ 416, 'Requested Range Not Satisfiable' ],
|
||||
[ 417, 'Expectation Failed' ],
|
||||
[ 418, 'Im ATeapot' ],
|
||||
[ 421, 'Too Many Connections From This IP' ],
|
||||
[ 426, 'Upgrade Required' ],
|
||||
[ 429, 'Too Many Requests' ],
|
||||
[ 450, 'Blocked By Windows Parental Controls' ],
|
||||
[ 494, 'Request Header Too Large' ],
|
||||
[ 497, 'HTTPTo HTTPS' ],
|
||||
[ 499, 'Client Closed Request' ],
|
||||
[ 500, 'Internal Server Error' ],
|
||||
[ 501, 'Not Implemented' ],
|
||||
[ 502, 'Bad Gateway' ],
|
||||
[ 503, 'Service Unavailable' ],
|
||||
[ 504, 'Gateway Timeout' ],
|
||||
[ 505, 'HTTPVersion Not Supported' ],
|
||||
[ 506, 'Variant Also Negotiates' ],
|
||||
[ 510, 'Not Extended' ]
|
||||
];
|
||||
|
||||
500: 'Internal Server Error',
|
||||
501: 'Not Implemented',
|
||||
502: 'Bad Gateway',
|
||||
503: 'Service Unavailable',
|
||||
504: 'Gateway Timeout',
|
||||
505: 'HTTPVersion Not Supported',
|
||||
506: 'Variant Also Negotiates',
|
||||
510: 'Not Extended'
|
||||
};
|
||||
|
||||
_.each(statusCodes, function createStatusCodeError(names, status) {
|
||||
_.each(statusCodes, function createStatusCodeError(tuple) {
|
||||
var status = tuple[0];
|
||||
var names = tuple[1];
|
||||
var allNames = [].concat(names, status);
|
||||
var primaryName = allNames[0];
|
||||
var className = _.studlyCase(primaryName);
|
||||
|
||||
@ -24,3 +24,11 @@ describe('Error Abstract', function () {
|
||||
expect(err.stack).to.be.a('string');
|
||||
});
|
||||
});
|
||||
|
||||
describe('StatusCodeError', function () {
|
||||
it('exposes status code as a number', function () {
|
||||
var err = new errors['404']();
|
||||
expect(err.status).to.be(404);
|
||||
expect(err.status).to.not.be('404');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user