Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

http-errors

Package Overview
Dependencies
Maintainers
3
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

http-errors - npm Package Compare versions

Comparing version 1.2.8 to 1.3.0

8

HISTORY.md

@@ -0,1 +1,9 @@

2015-02-01 / 1.3.0
==================
* Construct errors using defined constructors from `createError`
* Fix error names that are not identifiers
- `createError["I'mateapot"]` is now `createError.ImATeapot`
* Set a meaningful `name` property on constructed errors
2014-12-09 / 1.2.8

@@ -2,0 +10,0 @@ ==================

47

index.js

@@ -5,2 +5,8 @@

function toIdentifier(str) {
return str.split(' ').map(function (token) {
return token.slice(0, 1).toUpperCase() + token.slice(1)
}).join('').replace(/[^ _0-9a-z]/gi, '')
}
exports = module.exports = function httpError() {

@@ -32,13 +38,24 @@ // so much arity going on ~_~

if (typeof status !== 'number' || !statuses[status]) status = 500;
if (typeof status !== 'number' || !statuses[status]) {
status = 500
}
// constructor
var HttpError = exports[status]
if (!err) {
// create error
err = new Error(msg || statuses[status])
err = HttpError
? new HttpError(msg)
: new Error(msg || statuses[status])
Error.captureStackTrace(err, httpError)
}
err.expose = status < 500;
if (!HttpError || !(err instanceof HttpError)) {
// add properties to generic error
err.expose = status < 500
err.status = err.statusCode = status
}
for (var key in props) err[key] = props[key];
err.status = err.statusCode = status;
return err;

@@ -53,2 +70,5 @@ };

codes.forEach(function (code) {
var name = toIdentifier(statuses[code])
var className = name.match(/Error$/) ? name : name + 'Error'
if (code >= 500) {

@@ -59,2 +79,8 @@ var ServerError = function ServerError(msg) {

self.__proto__ = ServerError.prototype
Object.defineProperty(self, 'name', {
enumerable: false,
configurable: true,
value: className,
writable: true
})
return self

@@ -67,3 +93,3 @@ }

exports[code] =
exports[statuses[code].replace(/\s+/g, '')] = ServerError;
exports[name] = ServerError
return;

@@ -76,2 +102,8 @@ }

self.__proto__ = ClientError.prototype
Object.defineProperty(self, 'name', {
enumerable: false,
configurable: true,
value: className,
writable: true
})
return self

@@ -84,4 +116,7 @@ }

exports[code] =
exports[statuses[code].replace(/\s+/g, '')] = ClientError;
exports[name] = ClientError
return;
});
// backwards-compatibility
exports["I'mateapot"] = exports.ImATeapot

13

package.json
{
"name": "http-errors",
"description": "Create HTTP error objects",
"version": "1.2.8",
"author": {
"name": "Jonathan Ong",
"email": "me@jongleberry.com",
"url": "http://jongleberry.com",
"twitter": "https://twitter.com/jongleberry"
},
"version": "1.3.0",
"author": "Jonathan Ong <me@jongleberry.com> (http://jongleberry.com)",
"contributors": [
"Alan Plum <me@pluma.io>",
"Douglas Christopher Wilson <doug@somethingdoug.com>"
],
"license": "MIT",

@@ -12,0 +11,0 @@ "repository": "jshttp/http-errors",

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