Skip to content

g2a-com/node-standard-error

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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);

About

Library extending javascript error

Resources

License

Stars

Watchers

Forks

Packages

No packages published