1.1.8 • Published 10 months ago

souq-error-handler v1.1.8

Weekly downloads
-
License
MIT
Repository
-
Last release
10 months ago

ErrorHandler

This project provides a customizable error handling library for Node.js applications. ErrorHandler sends alerts using Opsgenie, logs error messages to a file, and can be easily integrated into other projects.

Usage

To use the ErrorHandler in your project, first install it as a dependency:

Add the following values do your .env file

OPSGENIE_GENERIC_CHANNEL_API_KEY=your_api_key
PRODUCTION_CRITICAL_SLACK_ALERT_CHANNEL_ID=PRODUCTION_CRITICAL_SLACK_ALERT_CHANNEL_ID
LOG_FILE_PATH=/path/to/error.log
npm install --save souq-error-handler

Then, import and use the ErrorHandler in your project:

const ErrorHandler = require('errorHandler');

// Initialize ErrorHandler instance
const errorHandler = new ErrorHandler(
  process.env.OPSGENIE_GENERIC_CHANNEL_API_KEY || '',
  process.env.LOG_FILE_PATH || 'error.log'
);

// Log error to file
errorHandler.logError('Logging an example error message into the error.log');

// Send error to team devices with specified severity
errorHandler.slackAlert('Logging an example critical error message into the slack', 'critical').catch((err) => {
    console.error('A critical slack alert:', err);
});

errorHandler.slackAlert('Logging an example moderate error message into the slack', 'moderate').catch((err) => {
    console.error('A moderate slack alert:', err);
});

// Send error to team devices and send generic alert
errorHandler.genericAlert('Logging an example error directly to team devices').catch((err) => {
    console.error('A generic alert:', err);
});

Running Tests

To run tests, execute the following command:

npm test

Linting

This project uses ESLint for linting. To fix linting issues, run:

npm run lint --fix

Further Development

  1. Clone this repository:
git clone https://github.com/yourusername/errorHandler.git
  1. Install dependencies:
npm install
  1. Copy the .env.example file to create a new .env file:
cp .env.example .env
  1. Update the .env file with your API keys, recipients, and other configuration values.

  2. (optional) Run the example usage script to see what happens:

node src/example_usage.js

Folder Structure

|-- .env
|-- .env.example
|-- .eslintignore
|-- .eslintrc.json
|-- .gitignore
|-- README.md
|-- index.js
|-- package-lock.json
|-- package.json
|-- src
|   |-- errorHandler.js
|   |-- example_usage.js
|-- tests
    |-- errorHandler.test.js
1.1.1

12 months ago

1.1.0

12 months ago

1.1.8

10 months ago

1.1.7

10 months ago

1.1.6

10 months ago

1.1.5

10 months ago

1.1.4

11 months ago

1.1.3

11 months ago

1.1.2

12 months ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago