JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 32
  • Score
    100M100P100Q55526F
  • License MIT

Helper to deal with errors lifecycle in javascript

Package Exports

  • bugsy

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (bugsy) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

bugsy NPM version Build Status ESLint Config

Helper to deal with errors lifecycle in javascript.

Dealing with errors is a common problem in every small or large project. While a lot of libraries simply focus on their creation, this library is meant to deal with their lifecycle.

Features

  • Universal module
  • Error severity
  • Custom metadata
  • Flowtype

Installation

NPM

With NPM:

$ npm install bugsy

With Yarn:

$ yarn add bugsy

Usage

import * as bugsy from 'bugsy';

const RAN_AWAY = 'ran_away';
const THROW_MISSED = 'throw_missed';

const ranAway = bugsy.createDynamicError(RAN_AWAY, (name) => `${name} ran away, again`);
const throwMissed = bugsy.createError(THROW_MISSED, 'Throw totally missed');

function capture(name) {
  const r = Math.random();

  if (r < 0.3) {
    throw throwMissed();
  } else if (r < 0.6) {
    throw ranAway(name);
  } else {
    throw new Error();
  }
}

function handler(fn) {
  try {
    fn();
  } catch (err) {
    console.log(bugsy.toString(err));
  }
}

handler(() => {
  try {
    capture('Abra');
  } catch (err) {
    switch (err.code) {
      case THROW_MISSED:
        console.log('Oh well...');
        break;
      case RAN_AWAY:
        throw err.setSeverity(bugsy.syslog.CRITICAL).addMeta({ firstTry: true });
      default:
        throw bugsy.convert(err).setSeverity(bugsy.syslog.EMERGENCY);
    }
  }
});

Licences

njakob/bugsy is licensed under the MIT License.