Skip to content

A simple extendable error class that extends Error.

Notifications You must be signed in to change notification settings

vilicvane/extendable-error

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Extendable Error

YOU PROBABLY DON'T NEED THIS PACKAGE ANYMORE.

The 6 lines of code below works well enough in modern JavaScript engines:

export abstract class ExtendableError extends Error {
  constructor(message?: string) {
    super(message);
    this.name = new.target.name;
  }
}

A simple abstract extendable error class that extends Error, which handles the error name, message and stack property.

Install

npm install extendable-error --save

Usage

import ExtendableError from "extendable-error";

class SomeError extends ExtendableError {
  constructor(message: string, public code: number) {
    super(message);
  }
}

let someError = new SomeError("Some error", 0x0001);

License

MIT License.

About

A simple extendable error class that extends Error.

Resources

Stars

Watchers

Forks

Packages

No packages published