Skip to content

Latest commit

 

History

History
42 lines (29 loc) · 767 Bytes

README.md

File metadata and controls

42 lines (29 loc) · 767 Bytes

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.