1.0.3 • Published 10 years ago

@hexeo/abstract-error v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
10 years ago

AbstractError Build Status

Description

Provide a sexy way to extends the default javascript Error object.

Install

npm install @hexeo/abstract-error

Usages

Define a new error type

Simple

import AbstractError from '@hexeo/abstract-error';

class MyError extends AbstractError {
  constructor (message) {
    super (message);
  }
}

With custom properties

import AbstractError from '@hexeo/abstract-error';

class MyError extends AbstractError {
  constructor (message) {
    super (message);

    this.code = 500;
    this.reason = 'oups';
  }
}

With predefined message

import AbstractError from '@hexeo/abstract-error';

class MyError extends AbstractError {
  constructor () {
    super ();
  }

  this.message = 'Oups, something went wrong';
}

With custom constructor parameters

import AbstractError from '@hexeo/abstract-error';

class MyError extends AbstractError {
  constructor (message, foo, bar) {
    super (message);

    this.foo = foo;
    this.bar = bar;
  }
}

Throw and catch the error

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
  }
}
1.0.3

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago