6.0.2 • Published 6 months ago

@ezez/errors v6.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

@ezez/errors

JavaScript's errors with superpowers! ⚡

Features:

  • 🛠 First class TypeScript support - 100% type safe and intellisense friendly
  • 📝 Attach extra data to an error - debug with ease
  • 🪬 Give your errors a meaningful name - improve code readability
  • 🧱 Build your errors on top of another - access the whole hierarchy
  • 🌟 Bonus features - clean up your stack traces, normalize non-errors
  • 📦 No dependencies - use it anywhere
  • 🌎 Universal - exposes both ESM modules and CommonJS

Usage

Full documentation, including TypeScript usage available here: documentation.

npm i @ezez/errors --save

import { createError } from "@ezez/errors";
// or const { createError } = require("@ezez/errors");

const DatabaseError = createError("DatabaseError");
const QueryError = createError("QueryError", DatabaseError); // it extends `Error` by default, but you can pass another error
const InsertQueryError = createError("InsertQueryError", QueryError, { cleanStackTraces: false });

// then

try {
    throw new DatabaseError("Connection lost", { date: Date.now(), { ... } });
}
catch (e) {
    if (e instanceof DatabaseError) {
        console.error(e.details?.date, e.message);
    }
}

License

MIT

6.0.2

6 months ago

6.0.1

11 months ago

6.0.0

1 year ago

6.0.0-beta.1

1 year ago

5.0.0

1 year ago