Skip to content

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

License

Notifications You must be signed in to change notification settings

seudev/js-error

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published