New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

boo-boo

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

boo-boo

Opinionated better errors for Node.js, browsers and React Native.

  • 1.0.0-alpha.10
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

boo-boo · npm

Opinionated better errors for Node.js, browsers and React Native.

Working on a project I sooner or later come to a point where I would like to have my own errors, that can be easily distinguished from all other errors as well as from each other. Another quite important need is to send error messages and stack traces as JSON responses, but since native errors are missing toJSON() method they can't be properly stringified.

Table of Contents

Install

$ yarn add boo-boo

or

$ npm install --save boo-boo 

Usage

import boo from 'boo-boo';
// or
const boo = require('boo-boo');

// ...

try {
    JSON.parse(someJsonString);
}
catch (err) {
    throw new boo.Validation(err);
}

API

new boo.[name]([messageOrError])

A Boo constructor, inherited from Error. Each variant creates an instance of Boo with a specific name property. For a list of all available names see names.

Arguments

  • [messageOrError] (any|Error): Optional. Error description that will be coerced to a string. If the value is an instance of Error, its message property will be taken instead.

Examples

const err = new boo.Internal('boo!');
console.log(err.message); // 'boo!'

const err = new boo.Request(new TypeError('boo!'));
console.log(err.message); // 'boo!'

Boo

An instance of Boo created by one of constructors above.

Properties

  • name (String): Error name that is set upon creation. See names for all available names.
  • message (String): Optional. Human-readable description of the error.
  • stack (String): Stack trace.
  • isBoo (Boolean): A readonly property that always returns true to simplify error instance checking of Boo. It's intended to replace a somewhat ugly and counter-intuitive err instanceof boo.Internal with a much more slick err.isBoo.

Methods

  • toString()String: Overrides the default Error#toString() method in order to provide additional data.
  • toJSON()Object: A plain object representation that is required for JSON.stringify(). The resulting object contains name, message and stack properties (if exist).

names

A plain object of names used by Boo constructors:

  • Database
  • External
  • Internal
  • Request
  • Timeout
  • Validation

This list can be supplemented, PRs are welcome.

Examples

const err = new boo.Internal();
console.log(err.name === boo.names.Internal); // true

Keywords

FAQs

Package last updated on 09 Jun 2017

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