Socket
Book a DemoInstallSign in
Socket

@hexeo/abstract-error

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hexeo/abstract-error

Abstract Error Class

latest
Source
npmnpm
Version
1.0.3
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

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

FAQs

Package last updated on 18 Oct 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.