@ianwalter/base-error

6.1.0 • Public • Published

@ianwalter/base-error

A general base Error class that can be extended to create custom Error classes

npm page CI

Installation

npm install @ianwalter/base-error --save

Usage

import BaseError from '@ianwalter/base-error'

// Extend BaseError to create your custom error and optionally pass additional
// data to be included in the error message.
class SomeError extends BaseError {
  constructor (details) {
    super('Something happened', details)
  }
}

// Implementation example:
const someError = new SomeError({ user: 1 })
if (someError instanceof SomeError) {
  console.error(someError)
}
/*
Logs an error like:

SomeError: Something happened
{
  "user": 1
}
(stacktrace)
*/

License

Hippocratic License - See LICENSE

 

Created by Ian Walter

Package Sidebar

Install

npm i @ianwalter/base-error

Weekly Downloads

20

Version

6.1.0

License

SEE LICENSE IN LICENSE

Unpacked Size

4.93 kB

Total Files

7

Last publish

Collaborators

  • ianwalter