@ianwalter/base-error

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

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
@ianwalter/base-error
6.1.03 years ago5 years agoMinified + gzip package size for @ianwalter/base-error in KB

Readme

@ianwalter/base-error
A general base Error class that can be extended to create custom Error classes

!npm pagenpmImagenpmUrl !CIciImageciUrl

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 LICENSElicenseUrl
 
Created by Ian Walter