# taticbr-notify-error

> This project contains a code to save errors and send them by notification adapter to your nest.js project.

Latest version **1.2.6** (published 2022-05-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install taticbr-notify-error
pnpm add taticbr-notify-error
yarn add taticbr-notify-error
bun add taticbr-notify-error
```

## Health

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

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

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.6 |
| Published | 2022-05-19 |
| First published | 2022-03-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 4 |
| Unpacked size | 154.3 KB |
| Known vulnerabilities | 0 (+3 in 2 direct dependencies) |
| Install scripts | no |
| Author | tatic |
| Maintainers | tatic |

## Links

- npm: https://www.npmjs.com/package/taticbr-notify-error
- npm.io page: https://npm.io/package/taticbr-notify-error

## Dependencies (4)

- [mongoose](https://npm.io/package/mongoose.md) ^6.0.9
- [@nestjs/core](https://npm.io/package/@nestjs/core.md) ^8.4.2
- [@nestjs/common](https://npm.io/package/@nestjs/common.md) ^8.0.0
- [@nestjs/schedule](https://npm.io/package/@nestjs/schedule.md) ^1.0.2

## Recent versions

- 1.2.6 (latest) — 2022-05-19
- 1.2.5 — 2022-05-06
- 1.2.4 — 2022-05-06
- 1.2.3 — 2022-04-07
- 1.1.3 — 2022-04-07
- 1.1.2 — 2022-04-07
- 1.1.1 — 2022-04-07
- 1.1.0 — 2022-04-07
- 1.0.2 — 2022-04-07
- 1.0.1 — 2022-03-30
- 1.0.0 — 2022-03-30

## README

This project contains a code to save errors and send them by notification adapter to your nest.js project.

# Installation

```bash
npm install taticbr-notify-error
```

or

```bash
yarn add taticbr-notify-error
```

# How to use

## Implementing on your application

First, import `NotifyErrorModule` and imports it in your module, don't forget to provide your Event Emitter Adapter and mongoDB connection.

Example:

```typescript
import { Module } from '@nestjs/common';
import {
  EventEmitterAdapter,
  EventEmitterProvider,
} from 'src/infrastructure/adapters/eventEmitter/';
import { NotifyErrorModule } from 'taticbr-notify-error';

@Module({
  imports: [
    NotifyErrorModule.forRoot({
      eventEmitterAdapter: EventEmitterAdapter,
      mongoUrl: 'mongodb://localhost:27017/DBName',
    }),
  ],
  providers: [EventEmitterProvider],
})
export class PimModule {}
```

Event Emitter should follow abstract class definition:

```typescript
export abstract class EventEmitterPort {
  request: (topic: string, payload: unknown) => Promise<void>;
}
```

## Saving error to notify

To save an error, you must import `SaveNotifyError` class, create it instance on your service and use like the following example:

```typescript
import { Injectable } from '@nestjs/common';
import { SaveNotifyError } from 'taticbr-notify-error';

@Injectable()
export class MyService {
  constructor(private readonly saveError: SaveNotifyError) {}

  private async execute() {
    try {
      // ... execution ...
    } catch (error) {
      this.saveError.save({ error: error.message, errorType: 'pim' });
    }
  }
}
```

# Configuration

You can configure this module by setting some environemnt variables

| Environment Variables         |                                         Utility                                          |         Default         |
| ----------------------------- | :--------------------------------------------------------------------------------------: | :---------------------: |
| VERIFY_ERROR_SCHEDULE_CRON    | Defines a cron expression to define at what delay the error submit task runner will run. |     every one hour      |
| PROCESS_ERROR_COLLECTION_NAME |                 Defines the mongo collection name to save process errors                 |      processError       |
| EVENT_EMITTER_TOPIC           |           Defines the name of the topic that will be sent to the event emitter           | NotifyLoadPimDelayTopic |

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