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
npmi i @franzzemen/enhanced-error
const EnhancedError = require('@franzzemen/enhanced-error').EnhancedError;
import{EnhancedError} from '@franzzemen/enhanced-error';
- Log an error and rethrow, passing only the string for the error. It will
logErroandThrow('This is an error');
- Log an error and rethrow, passing the Error
logErrorAndThrow(new Error('This is an Error'));
- Log an error and rethrow, passing the LoggerAdapter
const log = new LoggerAdapter({...}, 'some-module', 'some-source', 'some-method');
logErrorAndThrow('This is an Error', log);
- 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);