Skip to content

A library that streamlines creation of custom error classes with message registries.

License

Notifications You must be signed in to change notification settings

Thundercraft5/node-errors

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

70 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

node-errors is a library that streamlines the creation and management of message-coded errors. Has 0 dependencies!

Usage

Use makeErrors(messages, errorMap, includeNativeCodes?) to create coded error classes.

import makeErrors from "@thundercraft5/node-errors";

const { MyError } = makeErrors({
    "TEST_CODE": "This is a test message!",
}, {
    MyError: class MyError extends Error {},
}, /* set this parameter to `true` to include built-in codes in the available messages */ false);

throw new MyError("TEST_CODE"); // MyError [TEST_CODE]: This is a test message!

Alternatively, use the built-in error classes instead.

import { Error } from "@thundercraft5/node-errors";

throw new Error("METHOD_NOT_IMPLEMENTED", Error, "test"); // Error [METHOD_NOT_IMPLEMENTED]: Method Error#test() is not implemented.

NOTES:

  • Targeted/Built for ESNext.
  • ESM-Only.
  • May be run in the browser with a bundler.

About

A library that streamlines creation of custom error classes with message registries.

Resources

License

Stars

Watchers

Forks

Packages

No packages published