Socket
Socket
Sign inDemoInstall

http-errors

Package Overview
Dependencies
5
Maintainers
3
Versions
29
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.7.3 to 1.8.0

6

HISTORY.md

@@ -0,1 +1,7 @@

2020-06-29 / 1.8.0
==================
* Add `isHttpError` export to determine if value is an HTTP error
* deps: setprototypeof@1.2.0
2019-06-24 / 1.7.3

@@ -2,0 +8,0 @@ ==================

37

index.js

@@ -28,2 +28,3 @@ /*!

module.exports.HttpError = createHttpErrorConstructor()
module.exports.isHttpError = createIsHttpErrorFunction(module.exports.HttpError)

@@ -134,3 +135,3 @@ // Populate exports for all constructors

function createClientErrorConstructor (HttpError, name, code) {
var className = name.match(/Error$/) ? name : name + 'Error'
var className = toClassName(name)

@@ -178,2 +179,23 @@ function ClientError (message) {

/**
* Create function to test is a value is a HttpError.
* @private
*/
function createIsHttpErrorFunction (HttpError) {
return function isHttpError (val) {
if (!val || typeof val !== 'object') {
return false
}
if (val instanceof HttpError) {
return true
}
return val instanceof Error &&
typeof val.expose === 'boolean' &&
typeof val.statusCode === 'number' && val.status === val.statusCode
}
}
/**
* Create a constructor for a server error.

@@ -184,3 +206,3 @@ * @private

function createServerErrorConstructor (HttpError, name, code) {
var className = name.match(/Error$/) ? name : name + 'Error'
var className = toClassName(name)

@@ -271,1 +293,12 @@ function ServerError (message) {

}
/**
* Get a class name from a name identifier.
* @private
*/
function toClassName (name) {
return name.substr(-5) !== 'Error'
? name + 'Error'
: name
}

26

package.json
{
"name": "http-errors",
"description": "Create HTTP error objects",
"version": "1.7.3",
"version": "1.8.0",
"author": "Jonathan Ong <me@jongleberry.com> (http://jongleberry.com)",

@@ -15,3 +15,3 @@ "contributors": [

"inherits": "2.0.4",
"setprototypeof": "1.1.1",
"setprototypeof": "1.2.0",
"statuses": ">= 1.5.0 < 2",

@@ -21,11 +21,11 @@ "toidentifier": "1.0.0"

"devDependencies": {
"eslint": "5.16.0",
"eslint-config-standard": "12.0.0",
"eslint-plugin-import": "2.18.0",
"eslint-plugin-markdown": "1.0.0",
"eslint-plugin-node": "8.0.1",
"eslint-plugin-promise": "4.1.1",
"eslint-plugin-standard": "4.0.0",
"istanbul": "0.4.5",
"mocha": "6.1.4"
"eslint": "6.8.0",
"eslint-config-standard": "14.1.1",
"eslint-plugin-import": "2.22.0",
"eslint-plugin-markdown": "1.0.2",
"eslint-plugin-node": "11.1.0",
"eslint-plugin-promise": "4.2.1",
"eslint-plugin-standard": "4.0.1",
"mocha": "8.0.1",
"nyc": "15.1.0"
},

@@ -38,4 +38,4 @@ "engines": {

"test": "mocha --reporter spec --bail",
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot",
"test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter dot"
"test-ci": "nyc --reporter=text npm test",
"test-cov": "nyc --reporter=html --reporter=text npm test"
},

@@ -42,0 +42,0 @@ "keywords": [

@@ -91,2 +91,10 @@ # http-errors

### createError.isHttpError(val)
Determine if the provided `val` is an `HttpError`. This will return `true`
if the error inherits from the `HttpError` constructor of this module or
matches the "duck type" for an error this module creates. All outputs from
the `createError` factory will return `true` for this function, including
if an non-`HttpError` was passed into the factory.
### new createError\[code || name\](\[msg]\))

@@ -93,0 +101,0 @@

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc