httperrors
Advanced tools
Comparing version 0.4.1 to 0.5.0
@@ -1,81 +0,71 @@ | ||
(function (root, factory) { | ||
if (typeof exports === 'object') { | ||
module.exports = factory(require('createerror')); | ||
} else if (typeof define === 'function' && define.amd) { | ||
define(['createError'], factory); | ||
} else { | ||
root.httpErrors = factory(root.createError); | ||
} | ||
}(this, function (createError) { | ||
// Copied from /lib/_http_server.js (node.js@2900f07): | ||
var httpErrorNameByStatusCode = { | ||
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', // RFC 2324 | ||
422: 'Unprocessable Entity', // RFC 4918 | ||
423: 'Locked', // RFC 4918 | ||
424: 'Failed Dependency', // RFC 4918 | ||
425: 'Unordered Collection', // RFC 4918 | ||
426: 'Upgrade Required', // RFC 2817 | ||
428: 'Precondition Required', // RFC 6585 | ||
429: 'Too Many Requests', // RFC 6585 | ||
431: 'Request Header Fields Too Large', // RFC 6585 | ||
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', // RFC 2295 | ||
507: 'Insufficient Storage', // RFC 4918 | ||
509: 'Bandwidth Limit Exceeded', | ||
510: 'Not Extended', // RFC 2774 | ||
511: 'Network Authentication Required' // RFC 6585 | ||
}; | ||
var createError = require('createerror'); | ||
var httpErrors = {}; | ||
// Copied from /lib/_http_server.js (node.js@2900f07): | ||
var httpErrorNameByStatusCode = { | ||
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', // RFC 2324 | ||
422: 'Unprocessable Entity', // RFC 4918 | ||
423: 'Locked', // RFC 4918 | ||
424: 'Failed Dependency', // RFC 4918 | ||
425: 'Unordered Collection', // RFC 4918 | ||
426: 'Upgrade Required', // RFC 2817 | ||
428: 'Precondition Required', // RFC 6585 | ||
429: 'Too Many Requests', // RFC 6585 | ||
431: 'Request Header Fields Too Large', // RFC 6585 | ||
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', // RFC 2295 | ||
507: 'Insufficient Storage', // RFC 4918 | ||
509: 'Bandwidth Limit Exceeded', | ||
510: 'Not Extended', // RFC 2774 | ||
511: 'Network Authentication Required' // RFC 6585 | ||
}; | ||
/// Map the error codes/names, as defined in Node's [http | ||
/// module](http://nodejs.org/docs/latest/api/http.html). | ||
Object.keys(httpErrorNameByStatusCode).forEach(function (statusCode) { | ||
statusCode = +statusCode; // turn into a number | ||
var httpErrorName = httpErrorNameByStatusCode[statusCode]; | ||
var httpErrors = module.exports = {}; | ||
// Only include 4xx and 5xx | ||
if (statusCode < 400) { | ||
return; | ||
} | ||
/// Map the error codes/names, as defined in Node's [http | ||
/// module](http://nodejs.org/docs/latest/api/http.html). | ||
Object.keys(httpErrorNameByStatusCode).forEach(function (statusCode) { | ||
statusCode = +statusCode; // turn into a number | ||
var httpErrorName = httpErrorNameByStatusCode[statusCode]; | ||
// Invent a type by camel casing the usual message and removing | ||
// non-alphabetical chars | ||
var name = httpErrorName.replace(/ ([a-z])/gi, function ($0, $1) { | ||
return $1.toUpperCase(); | ||
}).replace(/[^a-z]/gi, ''); | ||
// Only include 4xx and 5xx | ||
if (statusCode < 400) { | ||
return; | ||
} | ||
// Add the error to the exported object and alias it as `statusCode` | ||
// allows for new httpErrors[res.statusCode] in a http proxying setting | ||
httpErrors[name] = httpErrors[statusCode] = createError({ | ||
statusCode: statusCode, | ||
status: statusCode, | ||
name: name | ||
}); | ||
// Invent a type by camel casing the usual message and removing | ||
// non-alphabetical chars | ||
var name = httpErrorName.replace(/ ([a-z])/gi, function ($0, $1) { | ||
return $1.toUpperCase(); | ||
}).replace(/[^a-z]/gi, ''); | ||
// Add the error to the exported object and alias it as `statusCode` | ||
// allows for new httpErrors[res.statusCode] in a http proxying setting | ||
httpErrors[name] = httpErrors[statusCode] = createError({ | ||
statusCode: statusCode, | ||
status: statusCode, | ||
name: name | ||
}); | ||
return httpErrors; | ||
})); | ||
}); |
@@ -15,3 +15,3 @@ { | ||
], | ||
"version": "0.4.1", | ||
"version": "0.5.0", | ||
"repository": { | ||
@@ -26,11 +26,19 @@ "type": "git", | ||
"dependencies": { | ||
"createerror": "0.4.0" | ||
"createerror": "0.4.1" | ||
}, | ||
"scripts": { | ||
"test": "mocha --recursive" | ||
}, | ||
"devDependencies": { | ||
"browserify": "^5.3.0", | ||
"mocha": "1.12.1", | ||
"uglifyjs": "^2.3.6", | ||
"unexpected": "=0.0.6" | ||
}, | ||
"scripts": { | ||
"dist": "mkdir -p dist && browserify ./lib/httpErrors.js -s httpErrors | uglifyjs -mc > ./dist/httpErrors.js", | ||
"prepublish": "npm run test && npm run dist", | ||
"test": "mocha --recursive" | ||
}, | ||
"files": [ | ||
"lib", | ||
"dist" | ||
], | ||
"publishConfig": { | ||
@@ -37,0 +45,0 @@ "repository": "http://registry.npmjs.org/" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
No License Found
License(Experimental) License information could not be found.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7902
4
4
1
65
3
2
+ Addedcreateerror@0.4.1(transitive)
- Removedcreateerror@0.4.0(transitive)
Updatedcreateerror@0.4.1