# souq-error-handler

> A simple error handler with Opsgenie integration

Latest version **1.1.8** (published 2023-07-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install souq-error-handler
pnpm add souq-error-handler
yarn add souq-error-handler
bun add souq-error-handler
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.8 |
| Published | 2023-07-04 |
| First published | 2023-05-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 10.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Your Name |
| Maintainers | oskii |

## Links

- npm: https://www.npmjs.com/package/souq-error-handler
- npm.io page: https://npm.io/package/souq-error-handler

## Dependencies (2)

- [dotenv](https://npm.io/package/dotenv.md) ^16.0.3
- [opsgenie-sdk](https://npm.io/package/opsgenie-sdk.md) ^0.5.1

## Recent versions

- 1.1.8 (latest) — 2023-07-04
- 1.1.7 — 2023-07-03
- 1.1.6 — 2023-07-03
- 1.1.5 — 2023-07-03
- 1.1.4 — 2023-06-23
- 1.1.3 — 2023-06-22
- 1.1.2 — 2023-05-29
- 1.1.1 — 2023-05-23
- 1.1.0 — 2023-05-23
- 1.0.4 — 2023-05-08
- 1.0.3 — 2023-05-08
- 1.0.2 — 2023-05-05
- 1.0.1 — 2023-05-04
- 1.0.0 — 2023-05-04

## README

# 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
```

```bash
npm install --save souq-error-handler
```
Then, import and use the ErrorHandler in your project:

```javascript
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:

```bash
npm test
```

## Linting
This project uses ESLint for linting. To fix linting issues, run:

```bash
npm run lint --fix
```

## Further Development

1. Clone this repository:

```bash
git clone https://github.com/yourusername/errorHandler.git
```

2. Install dependencies:

```bash
npm install
```

3. Copy the .env.example file to create a new .env file:

```bash
cp .env.example .env
```

4. Update the .env file with your API keys, recipients, and other configuration values.

5. (optional) Run the example usage script to see what happens:

```bash
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
```

---
_Source: https://npm.io/package/souq-error-handler · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
