JSPM

  • Created
  • Published
  • Downloads 487229
  • Score
    100M100P100Q184934F
  • License Apache-2.0

Custom error types and error factory functions

Package Exports

  • @thi.ng/errors
  • @thi.ng/errors/illegal-arguments
  • @thi.ng/errors/illegal-arity
  • @thi.ng/errors/illegal-state
  • @thi.ng/errors/unsupported

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@thi.ng/errors) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@thi.ng/errors

npm version npm downloads Twitter Follow

This project is part of the @thi.ng/umbrella monorepo.

About

Custom error types and error factory functions.

Additional error types can be defined using defError().

Status

STABLE - used in production

Installation

yarn add @thi.ng/errors

Package sizes (gzipped): ESM: 0.3KB / CJS: 0.3KB / UMD: 0.4KB

Dependencies

None

API

Generated API docs

import * as err from "@thi.ng/errors";

err.illegalArity(3)
// Error: illegal arity: 3

err.illegalArgs("expected foo");
// Error: illegal argument(s): expected foo

err.illegalState("oops");
// Error: illegal state: oops

err.unsupported("TODO not yet implemented")
// Error: unsupported operation: TODO not yet implemented

// define custom error
const MyError = err.defError(
    () => "Eeek... ",
    (x) => x + " is not allowed!"
);

try {
    throw new MyError(23);
} catch(e) {
    console.warn(e.message);
    console.log(e instanceof Error);
}
// Eeek... 23 is not allowed!
// true

Authors

Karsten Schmidt

License

© 2018 - 2020 Karsten Schmidt // Apache Software License 2.0