0.0.2 • Published 5 years ago

@seudev/js-error v0.0.2

Weekly downloads
1
License
Apache-2.0
Repository
github
Last release
5 years ago

JS Error

What is it?

A lightweight library, that provides an Error class to throws errors with cause, making it easier to chaining of errors.

Using JS Error

npm i @seudev/js-error

The JSError class is a subclass of Error class. Create instances of this class passing a message and a cause (optional). The message can be an string or an object.

throw new JSError("Foo");

throw new JSError("Foo", cause);

throw new JSError({name: "ValidationError", message: "Foo"}, cause);

throw new JSError({name: "ValidationError", message: "Foo"}, cause);

throw new JSError({name: "ValidationError", message: "Foo", data: {}}, cause);

With this class you can do error handling an throws a new error passing the cause of this error.

try {
    throw new Error("Foo");
} catch(ex) {
    throw new JSError("Bar", ex);
}

This code will generate a stacktrace like this:

stacktrace

Licensing

seudev/js-error is provided and distributed under the Apache Software License 2.0.

Refer to LICENSE for more information.