Provide a sexy way to extends the default javascript Error object.
npm install @hexeo/abstract-error
import AbstractError from '@hexeo/abstract-error';
class MyError extends AbstractError {
constructor (message) {
super (message);
}
}
import AbstractError from '@hexeo/abstract-error';
class MyError extends AbstractError {
constructor (message) {
super (message);
this.code = 500;
this.reason = 'oups';
}
}
import AbstractError from '@hexeo/abstract-error';
class MyError extends AbstractError {
constructor () {
super ();
}
this.message = 'Oups, something went wrong';
}
import AbstractError from '@hexeo/abstract-error';
class MyError extends AbstractError {
constructor (message, foo, bar) {
super (message);
this.foo = foo;
this.bar = bar;
}
}
import AbstractError from '@hexeo/abstract-error';
class MyError extends AbstractError {
constructor () {
super ();
this.message = 'Oups, something went wrong.';
this.code = 500;
this.reason = 'oups';
}
}
try {
throw new MyError();
} catch (error) {
if (error instanceof MyError) {
console.log(error.code); // 500
}
}