kind-error

Base class for easily creating meaningful and quiet by default Error classes.
Install
npm i kind-error --save
Features
- You can customize error name with
name
property in options object. - By default won't have
stack
property in the composed error object. - You should pass
showStack: true
in options if you want stacktraces. - Composes meaningful error output if
actual
andexpected
given. - If
actual
andexpected
is given, will composemessage
automatically.
Usage
For more use-cases see the tests
const KindError =
KindError
Initialize
KindError
class withmessage
andoptions
.
Params
message
{Object|String}[options]
{Object}showStack
{Boolean} iftrue
error will have.stack
propertydetailed
{Boolean} iftrue
more detailed.message
will be composed
returns
{Object}: instance of Error
Example
const err = 'msg' showStack: true custom: 123 console // => [KindError: msg]console // => 123console // => error stack trace
Or if you give actual
and expected
it will make default message
. See this example.
const assert = const err = actual: 1 2 3 expected: foo: 'bar' assertassertassertassertassertassertassertassert
Example AppError
Here we show how to create new error class
var util = var KindError = { KindError thisname = 'AppError'} util AppErrorprototype { return 123} var err = 'foo bar' baz: 'qux'//=> err// err.name => 'AppError'// err.message => 'foo bar'// err.baz => 'qux'// err.foo() => 123
Related
- abbrev-kindof: Use abbreviations for checking type of given value. Like
kindof(val, 'soa')
to check that value is string, object or array. - assert-kindof: Check native type of the given value and throw TypeError if not okey. Expressive, elegant, behavior-driven API, good descriptive default error messages, simple and clean syntax.
- is-kindof: Check type of given javascript value. Support promises, generators, streams, and native types. Thin wrapper around
kind-of
module. - kind-of-extra: Extends
kind-of
type check utility with support for promises, generators, streams and errors. Likekindof(Promise.resolve(1)) //=> 'promise'
and etc. - kind-of-types: List of all javascript types. Used and useful for checking, validation, sanitizing and testing. Like isStream, isPromise, isWeakset and etc.
- error-base: Create custom Error classes.
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
But before doing anything, please read the CONTRIBUTING.md guidelines.