Skip to content

FranzZemen/enhanced-error

Repository files navigation

Read Me

This small package provides Enhanced Errors capability

An Enhanced Error derives from Error. Functions are provided to avoid optimize code to log and throw, or log and return in the case of Promise body usage errors, leveraging the LoggerAdapter that can log to any JS logger. Its syntactical suger.

Both commonjs (require) and ECMAScript (import) loaders are supported

Install

npmi i @franzzemen/enhanced-error
const EnhancedError = require('@franzzemen/enhanced-error').EnhancedError;
import{EnhancedError} from '@franzzemen/enhanced-error';

Usage

  1. Log an error and rethrow, passing only the string for the error. It will
logErroandThrow('This is an error');
  1. Log an error and rethrow, passing the Error
logErrorAndThrow(new Error('This is an Error'));
  1. Log an error and rethrow, passing the LoggerAdapter
    const log = new LoggerAdapter({...}, 'some-module', 'some-source', 'some-method');
    logErrorAndThrow('This is an Error', log);
  1. Log an Error and rethrow, passing the ExecutiveContext (building the log from it)
    const log = new LoggerAdapter({...}, 'some-module', 'some-source', 'some-method');
    logErrorAndThrow('This is an Error', log);

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published