@thundercraft5/node-errors
TypeScript icon, indicating that this package has built-in type declarations

1.5.0 • Public • Published

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.

Package Sidebar

Install

npm i @thundercraft5/node-errors

Weekly Downloads

1

Version

1.5.0

License

MIT

Unpacked Size

101 kB

Total Files

37

Last publish

Collaborators

  • thundercraft5