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

abstract-error

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

abstract-error - npm Package Compare versions

Comparing version 2.0.0-alpha.7 to 2.0.0-alpha.8

2

lib/abstract-error.d.ts

@@ -19,2 +19,3 @@ export class AbstractError extends Error {

static createErrorClass(aType: string, aErrorCode?: number|string, ParentErrorClass?: typeof AbstractError): typeof AbstractError
static createErrorClass(aType: string, aErrorCode?: number|string|typeof AbstractError, ParentErrorClass?: typeof AbstractError): typeof AbstractError

@@ -46,3 +47,4 @@ /**

export function createErrorClass(aType: string, aErrorCode?: number|string, ParentErrorClass?: typeof AbstractError): typeof AbstractError
export function createErrorClass(aType: string, aErrorCode?: number|string|typeof AbstractError, ParentErrorClass?: typeof AbstractError): typeof AbstractError
export default AbstractError

6

lib/abstract-error.js

@@ -18,3 +18,3 @@ "use strict";

if (!new.target) return new AbstractError(msg, errno);
const ctor = this.constructor;
const ctor = this.hasOwnProperty('Class') && this.Class || this.constructor;
const self = Reflect.construct(Error, arguments, ctor);

@@ -33,3 +33,3 @@ // const self = Error.apply(this, arguments)

* @param {string} aType the error type
* @param {number|string} aErrorCode the error code, it should be not equal 0 if it's a number.
* @param {number|string|typeof AbstractError} aErrorCode the error code, it should be not equal 0 if it's a number.
* @param {typeof AbstractError} [ParentErrorClass] the parent error class. defaults to AbstractError

@@ -61,3 +61,3 @@ * @returns {typeof AbstractError} the new Error Class

}
const ctor = this.Class || this.constructor;
const ctor = this.hasOwnProperty('Class') && this.Class || this.constructor;
return Reflect.construct(ParentErrorClass, [msg, aCode], ctor);

@@ -64,0 +64,0 @@ }

@@ -31,2 +31,3 @@ import {AbstractError} from './abstract-error.js'

static createErrorClass(aType: string, aErrorCode?: number, ParentErrorClass?: typeof CommonError): typeof CommonError
static createErrorClass(aType: string, aErrorCode?: number|typeof CommonError, ParentErrorClass?: typeof CommonError): typeof CommonError

@@ -97,2 +98,10 @@ static isOk(err: CommonError): boolean

* @param {string} aType the error type(class) name
* @param {typeof CommonError} [ParentErrorClass] the parent error class. defaults to CommonError
* @returns {typeof CommonError} the new Error Class
*/
export function createErrorClass(aType: string, ParentErrorClass?: typeof CommonError): typeof CommonError
/**
* Create an Error Class
*
* @param {string} aType the error type(class) name
* @param {number} [aErrorCode] the error code, should be greater than 0.

@@ -103,1 +112,2 @@ * @param {typeof CommonError} [ParentErrorClass] the parent error class. defaults to CommonError

export function createCommonErrorClass(aType: string, aErrorCode?: number, ParentErrorClass?: typeof CommonError): typeof CommonError
export function createCommonErrorClass(aType: string, aErrorCode?: number|typeof CommonError, ParentErrorClass?: typeof CommonError): typeof CommonError

@@ -24,3 +24,3 @@ "use strict";

if (!new.target) return new CommonError();
const ctor = this.Class || this.constructor;
const ctor = this.hasOwnProperty('Class') && this.Class || this.constructor;
const self = Reflect.construct(_abstractError.AbstractError, arguments, ctor);

@@ -32,3 +32,3 @@ return self;

if (!new.target) return new NotImplementedError();
const ctor = this.Class || this.constructor;
const ctor = this.hasOwnProperty('Class') && this.Class || this.constructor;
const self = Reflect.construct(CommonError, ['NotImplemented', kNotSupported], ctor);

@@ -35,0 +35,0 @@ return self;

{
"name": "abstract-error",
"version": "2.0.0-alpha.7",
"version": "2.0.0-alpha.8",
"description": "abstract error class with error code supports to create error class quickly",

@@ -5,0 +5,0 @@ "homepage": "https://github.com/snowyu/abstract-error.js",

@@ -19,2 +19,3 @@ export class AbstractError extends Error {

static createErrorClass(aType: string, aErrorCode?: number|string, ParentErrorClass?: typeof AbstractError): typeof AbstractError
static createErrorClass(aType: string, aErrorCode?: number|string|typeof AbstractError, ParentErrorClass?: typeof AbstractError): typeof AbstractError

@@ -46,3 +47,4 @@ /**

export function createErrorClass(aType: string, aErrorCode?: number|string, ParentErrorClass?: typeof AbstractError): typeof AbstractError
export function createErrorClass(aType: string, aErrorCode?: number|string|typeof AbstractError, ParentErrorClass?: typeof AbstractError): typeof AbstractError
export default AbstractError

@@ -10,3 +10,3 @@ import { inherits } from 'inherits-ex'

if (!new.target) return new AbstractError(msg, errno)
const ctor = this.constructor
const ctor = (this.hasOwnProperty('Class') && this.Class) || this.constructor
const self = Reflect.construct(Error, arguments, ctor)

@@ -27,3 +27,3 @@ // const self = Error.apply(this, arguments)

* @param {string} aType the error type
* @param {number|string} aErrorCode the error code, it should be not equal 0 if it's a number.
* @param {number|string|typeof AbstractError} aErrorCode the error code, it should be not equal 0 if it's a number.
* @param {typeof AbstractError} [ParentErrorClass] the parent error class. defaults to AbstractError

@@ -53,3 +53,3 @@ * @returns {typeof AbstractError} the new Error Class

if (msg == null || msg === '') {msg = aType}
const ctor = this.Class || this.constructor
const ctor = (this.hasOwnProperty('Class') && this.Class) || this.constructor
return Reflect.construct(ParentErrorClass, [msg, aCode], ctor)

@@ -56,0 +56,0 @@ }

@@ -31,2 +31,3 @@ import {AbstractError} from './abstract-error.js'

static createErrorClass(aType: string, aErrorCode?: number, ParentErrorClass?: typeof CommonError): typeof CommonError
static createErrorClass(aType: string, aErrorCode?: number|typeof CommonError, ParentErrorClass?: typeof CommonError): typeof CommonError

@@ -97,2 +98,10 @@ static isOk(err: CommonError): boolean

* @param {string} aType the error type(class) name
* @param {typeof CommonError} [ParentErrorClass] the parent error class. defaults to CommonError
* @returns {typeof CommonError} the new Error Class
*/
export function createErrorClass(aType: string, ParentErrorClass?: typeof CommonError): typeof CommonError
/**
* Create an Error Class
*
* @param {string} aType the error type(class) name
* @param {number} [aErrorCode] the error code, should be greater than 0.

@@ -103,1 +112,2 @@ * @param {typeof CommonError} [ParentErrorClass] the parent error class. defaults to CommonError

export function createCommonErrorClass(aType: string, aErrorCode?: number, ParentErrorClass?: typeof CommonError): typeof CommonError
export function createCommonErrorClass(aType: string, aErrorCode?: number|typeof CommonError, ParentErrorClass?: typeof CommonError): typeof CommonError

@@ -19,3 +19,3 @@ import {createCtor, createFunction, inherits, setPrototypeOf} from 'inherits-ex'

if (!new.target) return new CommonError()
const ctor = this.Class || this.constructor
const ctor = (this.hasOwnProperty('Class') && this.Class) || this.constructor
const self = Reflect.construct(AbstractError, arguments, ctor)

@@ -28,3 +28,3 @@ return self

if (!new.target) return new NotImplementedError()
const ctor = this.Class || this.constructor
const ctor = (this.hasOwnProperty('Class') && this.Class) || this.constructor
const self = Reflect.construct(CommonError, ['NotImplemented', kNotSupported], ctor)

@@ -31,0 +31,0 @@ return self

@@ -23,2 +23,10 @@ import chai from 'chai';

});
it("test ES6 AbstractError Class", function() {
class MyError extends AbstractError {}
const err = new MyError("abstract error", 1);
assert.instanceOf(err, AbstractError);
assert.instanceOf(err, MyError);
assert.equal(err.code, 1);
assert.equal(err.message, "abstract error");
})
});

@@ -75,2 +83,15 @@

});
it("test ES6 AbstractError Class", function() {
var MyError = createErrorClass("MyClass", "MyErrCode");
class My1Error extends MyError {
name = 'My1Error'
}
var err = new My1Error("already read over error.");
assert.instanceOf(err, MyError);
assert.instanceOf(err, My1Error);
assert.instanceOf(err, AbstractError);
assert.equal(err.name, "My1Error");
assert.equal(err.message, "already read over error.");
assert.equal(err.code, "MyErrCode");
});
});
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