Socket
Book a DemoInstallSign in
Socket

@twuni/throwables

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@twuni/throwables

Extensible base classes for warnings, failures, and panic.

latest
Source
npmnpm
Version
0.1.0
Version published
Maintainers
1
Created
Source

Throwables.js

Extensible base classes for native JavaScript errors, providing more general support for different types of throwable things, like warnings, failures, and panic.

Features

  • Satisfies throwable instanceof Error
  • Extensible via ES6 class inheritance (unlike the native Error)
  • Provides a stack trace (via the #stack property)
  • Set additional properties upon initialization (no need to initialize, mutate, then throw)
  • Cleaner code, by making it easy to pass along additional context with a thrown object

Installing

Yarn

$ yarn add @twuni/throwables

NPM

$ npm install @twuni/throwables

Usage

import Failure from '@twuni/throwables/failure';

// Extend it like you would any other ES6 class
class AuthenticationFailure extends Failure {
  constructor(parameters = {}) {
    super({ message: 'Authentication failed', ...parameters });
  }
}

// Throw it like you would any other error
throw new AuthenticationFailure();

FAQs

Package last updated on 21 Nov 2018

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