Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
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

  • 1.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc