@mahdi.golzar/errorhandler

1.0.0 • Public • Published

ErrorHandler

ErrorHandler is a customizable error management package designed to enhance error handling in your applications. It allows you to log errors, send errors to external services, and define custom error-handling behavior.

Features

  • Error Logging: Automatically logs errors to the console and an internal log.
  • Error Reporting: Optionally sends errors to an external service.
  • Custom Error Handling: Allows you to define custom behavior for handling errors.
  • Error History: Maintains a log of all errors encountered.

Installation

No installation is required for this code as it is self-contained and can be added directly to your project.

Usage

  1. Create an ErrorHandler Instance
    const errorHandler = new ErrorHandler({
    logErrors: true, // Enable or disable error logging
    sendErrors: true, // Enable or disable error reporting to an external service
    customHandler: (error) => {
    console.error('Custom Error Handler:', error.message);
    // Add custom error handling logic here
    },
    });
  2. Handling Errors To handle an error, simply call the handleError method:
try {
throw new Error('Something went wrong!');
} catch (error) {
errorHandler.handleError(error);
}
  1. Accessing the Error Log To access the error log:
console.log('Error Log:', errorHandler.getErrorLog());

Readme

Keywords

Package Sidebar

Install

npm i @mahdi.golzar/errorhandler

Weekly Downloads

3

Version

1.0.0

License

ISC

Unpacked Size

3.7 kB

Total Files

3

Last publish

Collaborators

  • mahdi.golzar