https://github.com/vilicvane/extendable-error
A simple extendable error class that extends Error.
https://github.com/vilicvane/extendable-error
Last synced: 7 months ago
JSON representation
A simple extendable error class that extends Error.
- Host: GitHub
- URL: https://github.com/vilicvane/extendable-error
- Owner: vilicvane
- Created: 2015-12-30T16:21:58.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2023-05-12T10:52:34.000Z (about 2 years ago)
- Last Synced: 2024-11-30T15:41:55.093Z (7 months ago)
- Language: TypeScript
- Size: 75.2 KB
- Stars: 8
- Watchers: 2
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Extendable Error
**YOU PROBABLY DON'T NEED THIS PACKAGE ANYMORE.**
The 6 lines of code below works well enough in modern JavaScript engines:
```ts
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
```sh
npm install extendable-error --save
```## Usage
```ts
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.