1.2.6 • Published 2 years ago

taticbr-notify-error v1.2.6

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

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

Installation

npm install taticbr-notify-error

or

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:

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:

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:

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 VariablesUtilityDefault
VERIFY_ERROR_SCHEDULE_CRONDefines a cron expression to define at what delay the error submit task runner will run.every one hour
PROCESS_ERROR_COLLECTION_NAMEDefines the mongo collection name to save process errorsprocessError
EVENT_EMITTER_TOPICDefines the name of the topic that will be sent to the event emitterNotifyLoadPimDelayTopic
1.2.6

2 years ago

1.2.5

2 years ago

1.2.4

2 years ago

1.2.3

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago