JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 487453
  • Score
    100M100P100Q178755F
  • License Apache-2.0

Make your own error types, with a cause!

Package Exports

  • make-error-cause

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 (make-error-cause) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Make Error Cause

NPM version NPM downloads Build status Test coverage

Make your own error types, with a cause!

Features

  • Compatible with Node and browsers
  • Works with instanceof
  • Use error.stack and error.name
  • Appended cause with toString
  • Extends make-error

Installation

npm install make-error-cause --save

Usage

See the usages from make-error. Things work the same here, except the base function has a second argument for the "cause". The cause will be printed when using toString, but can also be accessed manually.

const CustomError = makeErrorCause('CustomError')

const cause = new Error('boom!')
const error = new CustomError('something bad', cause)

error.toString() //=> "CustomError: something bad\nCaused by: boom!"
error.stack // Works!
error.cause.stack // Handy!

Attribution

Inspired by verror, and others, but made much lighter for browser bundling in tight places.

License

Apache 2.0