Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bjyoungblood/es6-error
Easily-extendable error for use with ES6 classes
https://github.com/bjyoungblood/es6-error
Last synced: 5 days ago
JSON representation
Easily-extendable error for use with ES6 classes
- Host: GitHub
- URL: https://github.com/bjyoungblood/es6-error
- Owner: bjyoungblood
- License: mit
- Created: 2015-03-28T20:43:06.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2020-12-11T09:34:19.000Z (about 4 years ago)
- Last Synced: 2024-10-29T13:03:12.120Z (about 1 month ago)
- Language: JavaScript
- Size: 50.8 KB
- Stars: 213
- Watchers: 3
- Forks: 34
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
- awesome-github-star - es6-error - extendable error for use with ES6 classes | bjyoungblood | 216 | (JavaScript)
README
# es6-error
[![npm version](https://badge.fury.io/js/es6-error.svg)](https://www.npmjs.com/package/es6-error)
[![Build Status](https://travis-ci.org/bjyoungblood/es6-error.svg?branch=master)](https://travis-ci.org/bjyoungblood/es6-error)An easily-extendable error class for use with ES6 classes (or ES5, if you so
choose).Tested in Node 4.0, Chrome, and Firefox.
## Why?
I made this because I wanted to be able to extend Error for inheritance and type
checking, but can never remember to add
`Error.captureStackTrace(this, this.constructor.name)` to the constructor or how
to get the proper name to print from `console.log`.## ES6 Usage
```javascript
import ExtendableError from 'es6-error';
class MyError extends ExtendableError {
// constructor is optional; you should omit it if you just want a custom error
// type for inheritance and type checking
constructor(message = 'Default message') {
super(message);
}
}export default MyError;
```## ES5 Usage
```javascript
var util = require('util');
var ExtendableError = require('es6-error');function MyError(message) {
message = message || 'Default message';
ExtendableError.call(this, message);
}util.inherits(MyError, ExtendableError);
module.exports = MyError;
```### Known Issues
- Uglification can obscure error class names ([#31](https://github.com/bjyoungblood/es6-error/issues/31#issuecomment-301128220))
#### Todo
- Better browser compatibility
- Browser tests