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
Collection of helpers to deal with errors.
Dealing with errors is a common problem in every kind of project. While a lot of libraries simply focus on their creation, this library is meant to deal whole way through their lifecycle.
Features
- Isomorphic module
- Error severity support
- Flowtype support
Installation
$ npm install bugsyUsage
import * as bugsy from 'bugsy';
const CODE_RAN_AWAY = 'ran_away';
const CODE_THROW_MISSED = 'throw_missed';
const RanAwayError = bugsy.newError(CODE_RAN_AWAY, 'It ran away, again');
const ThrowMissedError = bugsy.newError(CODE_THROW_MISSED, 'Throw totally missed');
function capture() {
if (Math.random() > 0.9) {
throw new ThrowMissedError({ severity: bugsy.SYSLOG_WARNING });
} else {
throw new RanAwayError();
}
}
function handler(fn) {
try {
fn();
} catch (err) {
console.log(bugsy.toString(err));
}
}
handler(() => {
try {
capture();
} catch (err) {
switch (true) {
case err.code === CODE_THROW_MISSED:
break;
case err instanceof RanAwayError:
throw (err.addSeverity(bugsy.SYSLOG_EMERGENCY));
default:
throw err;
}
}
});Licences
Bugsy is licensed under the MIT License.
