Socket
Socket
Sign inDemoInstall

http-errors

Package Overview
Dependencies
4
Maintainers
3
Versions
29
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.5.1 to 1.6.0

9

HISTORY.md

@@ -0,1 +1,10 @@

2017-02-14 / 1.6.0
==================
* Accept custom 4xx and 5xx status codes in factory
* Add deprecation message to `"I'mateapot"` export
* Deprecate passing status code as anything except first argument in factory
* Deprecate using non-error status codes
* Make `message` property enumerable for `HttpError`s
2016-11-16 / 1.5.1

@@ -2,0 +11,0 @@ ==================

55

index.js

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

var deprecate = require('depd')('http-errors')
var setPrototypeOf = require('setprototypeof')

@@ -32,2 +33,11 @@ var statuses = require('statuses')

/**
* Get the code class of a status code.
* @private
*/
function codeClass (status) {
return Number(String(status).charAt(0) + '00')
}
/**
* Create a new HTTP Error.

@@ -58,2 +68,5 @@ *

status = arg
if (i !== 0) {
deprecate('non-first-argument status code; replace with createError(' + arg + ', ...)')
}
break

@@ -66,3 +79,8 @@ case 'object':

if (typeof status !== 'number' || !statuses[status]) {
if (typeof status === 'number' && (status < 400 || status >= 600)) {
deprecate('non-error status code; use only 4xx or 5xx status codes')
}
if (typeof status !== 'number' ||
(!statuses[status] && (status < 400 || status >= 600))) {
status = 500

@@ -72,3 +90,3 @@ }

// constructor
var HttpError = createError[status]
var HttpError = createError[status] || createError[codeClass(status)]

@@ -83,3 +101,3 @@ if (!err) {

if (!HttpError || !(err instanceof HttpError)) {
if (!HttpError || !(err instanceof HttpError) || err.status !== status) {
// add properties to generic error

@@ -124,3 +142,4 @@ err.expose = status < 500

// create the error object
var err = new Error(message != null ? message : statuses[code])
var msg = message != null ? message : statuses[code]
var err = new Error(msg)

@@ -133,2 +152,10 @@ // capture a stack trace to the construction point

// redefine the error message
Object.defineProperty(err, 'message', {
enumerable: true,
configurable: true,
value: msg,
writable: true
})
// redefine the error name

@@ -164,3 +191,4 @@ Object.defineProperty(err, 'name', {

// create the error object
var err = new Error(message != null ? message : statuses[code])
var msg = message != null ? message : statuses[code]
var err = new Error(msg)

@@ -173,2 +201,10 @@ // capture a stack trace to the construction point

// redefine the error message
Object.defineProperty(err, 'message', {
enumerable: true,
configurable: true,
value: msg,
writable: true
})
// redefine the error name

@@ -204,7 +240,7 @@ Object.defineProperty(err, 'name', {

switch (String(code).charAt(0)) {
case '4':
switch (codeClass(code)) {
case 400:
CodeError = createClientErrorConstructor(HttpError, name, code)
break
case '5':
case 500:
CodeError = createServerErrorConstructor(HttpError, name, code)

@@ -222,3 +258,4 @@ break

// backwards-compatibility
exports["I'mateapot"] = exports.ImATeapot
exports["I'mateapot"] = deprecate.function(exports.ImATeapot,
'"I\'mateapot"; use "ImATeapot" instead')
}

@@ -225,0 +262,0 @@

5

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

@@ -13,2 +13,3 @@ "contributors": [

"dependencies": {
"depd": "1.1.0",
"inherits": "2.0.3",

@@ -19,3 +20,3 @@ "setprototypeof": "1.0.2",

"devDependencies": {
"eslint": "3.10.2",
"eslint": "3.15.0",
"eslint-config-standard": "6.2.1",

@@ -22,0 +23,0 @@ "eslint-plugin-markdown": "1.0.0-beta.3",

@@ -47,4 +47,7 @@ # http-errors

be lower-cased
- `message`
- `status` and `statusCode` - the status code of the error, defaulting to `500`
- `message` - the traditional error message, which should be kept short and all
single line
- `status` - the status code of the error, mirroring `statusCode` for general
compatibility
- `statusCode` - the status code of the error, defaulting to `500`

@@ -51,0 +54,0 @@ ### createError([status], [message], [properties])

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