@g2a/standard-error
TypeScript icon, indicating that this package has built-in type declarations

1.3.3 • Public • Published

Standard error

Library extending javascript error.

Usage:

Creating new standard error:

  import BaseError from '@g2a/standard-error';

  class ExampleError extends BaseError {
    static defaultMessage = 'Example error';
  }

  // You can throw error with default message
  throw new ExampleError();

  // You can throw error with your own message
  throw new ExampleError('<NEW_MESSAGE>');

  // You can throw error with your own message, optional code and
  // some optional fields which will be converted to error details
  throw new ExampleError('<NEW_MESSAGE>', { code: '<ERROR_CODE>', foo: 'foo' });

  // You can throw error only with optional code
  // or some optional fields which will be converted to details
  throw new ExampleError({ code: '<ERROR_CODE>' });

Creating standard error based on normal error (or something else):

  import BaseError from '@g2a/standard-error';

  const error = new Error('<ERROR_MESSAGE>');
  const yourError = BaseError.from(error);

/@g2a/standard-error/

    Package Sidebar

    Install

    npm i @g2a/standard-error

    Weekly Downloads

    1

    Version

    1.3.3

    License

    MIT

    Unpacked Size

    19.5 kB

    Total Files

    8

    Last publish

    Collaborators

    • wadrian12
    • gpolek
    • qzb