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