Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var deprecate = require('depd')('http-errors')
var setPrototypeOf = require('setprototypeof')
var statuses = require('statuses')
var inherits = require('inherits')
var toIdentifier = require('toidentifier')
/**
* Module exports.
* @public
*/
module.exports = createError
module.exports.HttpError = createHttpErrorConstructor()
// Populate exports for all constructors
populateConstructorExports(module.exports, statuses.codes, module.exports.HttpError)
/**
* Get the code class of a status code.
* @private
*/
function codeClass (status) {
return Number(String(status).charAt(0) + '00')
}
/**
* Create a new HTTP Error.
*
* @returns {Error}
* @public
*/
// add properties to generic error
err.expose = status < 500
err.status = err.statusCode = status
}
for (var key in props) {
if (key !== 'status' && key !== 'statusCode') {
err[key] = props[key]
}
}
return err;
};
// create generic error objects
var codes = statuses.codes.filter(function (num) {
return num >= 400;
});
codes.forEach(function (code) {
var name = toIdentifier(statuses[code])
var className = name.match(/Error$/) ? name : name + 'Error'
if (code >= 500) {
var ServerError = function ServerError(msg) {
var self = new Error(msg != null ? msg : statuses[code])
Error.captureStackTrace(self, ServerError)
self.__proto__ = ServerError.prototype
Object.defineProperty(self, 'name', {
enumerable: false,
configurable: true,
value: className,
var deprecate = require('depd')('http-errors')
var setPrototypeOf = require('setprototypeof')
var statuses = require('statuses')
var inherits = require('inherits')
/**
* Module exports.
* @public
*/
module.exports = createError
module.exports.HttpError = createHttpErrorConstructor()
// Populate exports for all constructors
populateConstructorExports(module.exports, statuses.codes, module.exports.HttpError)
/**
* Get the code class of a status code.
* @private
*/
function codeClass (status) {
return Number(String(status).charAt(0) + '00')
}
/**
* Create a new HTTP Error.
*
* @returns {Error}
* @public
*/
Object.keys(codes).forEach((code) => {
const message = codes[code];
const status = Number(code);
// populate properties
statuses[status] = message;
statuses[message] = status;
statuses[message.toLowerCase()] = status;
// add to array
statuses.codes.push(status);
});
}
const statuses = require('statuses')
const names = {}
const messages = {}
const table = {}
/**
* Generate code to error and name to error mapping.
*
* Error have three fields
* * name
* * message
* * status
*/
statuses.codes.forEach((code) => {
const prefix = String(code).charAt(0)
if (prefix === '4' || prefix === '5') {
const name = toIdentifier(statuses[code])
names[code] = name
messages[code] = statuses[code]
table[name] = {
name,
message: statuses[code],
status: code
}
}
})
// generate error classes
/**
*/
var setPrototypeOf = require('setprototypeof')
var statuses = require('statuses')
var inherits = require('inherits')
/**
* Module exports.
* @public
*/
module.exports = createError
module.exports.HttpError = createHttpErrorConstructor()
// Populate exports for all constructors
populateConstructorExports(module.exports, statuses.codes, module.exports.HttpError)
/**
* Create a new HTTP Error.
*
* @returns {Error}
* @public
*/
function createError () {
// so much arity going on ~_~
var err
var msg
var status = 500
var props = {}
for (var i = 0; i < arguments.length; i++) {
var arg = arguments[i]
var deprecate = require('depd')('http-errors')
var setPrototypeOf = require('setprototypeof')
var statuses = require('statuses')
var inherits = require('inherits')
var toIdentifier = require('toidentifier')
/**
* Module exports.
* @public
*/
module.exports = createError
module.exports.HttpError = createHttpErrorConstructor()
// Populate exports for all constructors
populateConstructorExports(module.exports, statuses.codes, module.exports.HttpError)
/**
* Get the code class of a status code.
* @private
*/
function codeClass (status) {
return Number(String(status).charAt(0) + '00')
}
/**
* Create a new HTTP Error.
*
* @returns {Error}
* @public
*/
// add properties to generic error
err.expose = status < 500
err.status = err.statusCode = status
}
for (var key in props) {
if (key !== 'status' && key !== 'statusCode') {
err[key] = props[key]
}
}
return err;
};
// create generic error objects
var codes = statuses.codes.filter(function (num) {
return num >= 400;
});
codes.forEach(function (code) {
var name = toIdentifier(statuses[code])
var className = name.match(/Error$/) ? name : name + 'Error'
if (code >= 500) {
var ServerError = function ServerError(msg) {
var self = new Error(msg != null ? msg : statuses[code])
Error.captureStackTrace(self, ServerError)
self.__proto__ = ServerError.prototype
Object.defineProperty(self, 'name', {
enumerable: false,
configurable: true,
value: className,
var deprecate = require('depd')('http-errors')
var setPrototypeOf = require('setprototypeof')
var statuses = require('statuses')
var inherits = require('inherits')
/**
* Module exports.
* @public
*/
module.exports = createError
module.exports.HttpError = createHttpErrorConstructor()
// Populate exports for all constructors
populateConstructorExports(module.exports, statuses.codes, module.exports.HttpError)
/**
* Get the code class of a status code.
* @private
*/
function codeClass (status) {
return Number(String(status).charAt(0) + '00')
}
/**
* Create a new HTTP Error.
*
* @returns {Error}
* @public
*/
// add properties to generic error
err.expose = status < 500
err.status = err.statusCode = status
}
for (var key in props) {
if (key !== 'status' && key !== 'statusCode') {
err[key] = props[key]
}
}
return err;
};
// create generic error objects
var codes = statuses.codes.filter(function (num) {
return num >= 400;
});
codes.forEach(function (code) {
var name = toIdentifier(statuses[code])
var className = name.match(/Error$/) ? name : name + 'Error'
if (code >= 500) {
var ServerError = function ServerError(msg) {
var self = new Error(msg != null ? msg : statuses[code])
Error.captureStackTrace(self, ServerError)
self.__proto__ = ServerError.prototype
Object.defineProperty(self, 'name', {
enumerable: false,
configurable: true,
value: className,