Socket
Socket
Sign inDemoInstall

create-error-class

Package Overview
Dependencies
2
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.0 to 2.0.0

28

index.js
'use strict';
var util = require('util');
var objectAssign = require('object-assign');
var inherits = require('inherits');
var captureStackTrace = require('capture-stack-trace');
module.exports = function createErrorClass(className, constructor) {
module.exports = function createErrorClass(className, setup) {
if (typeof className !== 'string') {

@@ -11,21 +11,11 @@ throw new TypeError('Expected className to be a string');

constructor = constructor || function () {};
setup = setup || function () {};
function CustomError(message, props) {
Error.captureStackTrace(this, this.constructor);
this.name = className;
/* jshint evil:true */
var ErrorClass = eval('(function ' + className + '() { captureStackTrace(this, this.constructor); setup.apply(this, arguments); })');
if (typeof message !== 'string') {
props = message;
message = undefined;
}
inherits(ErrorClass, Error);
ErrorClass.prototype.name = className;
this.message = message;
objectAssign(this, props);
constructor.call(this);
}
util.inherits(CustomError, Error);
return CustomError;
return ErrorClass;
};
{
"name": "create-error-class",
"version": "1.0.0",
"version": "2.0.0",
"description": "Create Error classes",

@@ -25,3 +25,4 @@ "license": "MIT",

"dependencies": {
"object-assign": "^3.0.0"
"capture-stack-trace": "^1.0.0",
"inherits": "^2.0.1"
},

@@ -28,0 +29,0 @@ "devDependencies": {

@@ -18,4 +18,4 @@ # create-error-class [![Build Status](https://travis-ci.org/floatdrop/create-error-class.svg?branch=master)](https://travis-ci.org/floatdrop/create-error-class)

var HTTPError = createErrorClass('HTTPError', function () {
this.message = 'Status code is ' + this.statusCode;
var HTTPError = createErrorClass('HTTPError', function (props) {
this.message = 'Status code is ' + props.statusCode;
});

@@ -29,5 +29,5 @@

### createErrorClass(className, [constructor])
### createErrorClass(className, [setup])
Return constructor of Errors with `className`. Constructor accepts optional message and props, that will be assigned to Error.
Return constructor of Errors with `className`.

@@ -41,6 +41,6 @@ #### className

#### constructor
#### setup
Type: `function`
Function, that will be called after each Error object is created from constructor with context of Error object.
Setup function, that will be called after each Error object is created from constructor with context of Error object.

@@ -47,0 +47,0 @@ ## License

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