Socket
Socket
Sign inDemoInstall

httperrors

Package Overview
Dependencies
Maintainers
2
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

httperrors - npm Package Compare versions

Comparing version 0.4.1 to 0.5.0

dist/httpErrors.js

140

lib/httpErrors.js

@@ -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/"

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc