10.0.0 • Published 2 months ago

@schramautoparts/nest-bugsnag v10.0.0

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

Description

A Nest module wrapper for bugsnag-js logger.

Installation

$ npm i @schramautoparts/nest-bugsnag --save

Quick Start

Import the BugsnagModule into the module. For example AppModule:

import { Module } from '@nestjs/common';
import { BugsnagModule } from '@schramautoparts/nest-bugsnag';

@Module({
  imports: [
    // or registerAsync()
    BugsnagModule.register({
      apiKey: '<API_KEY>',
    }),
  ], 
  // Global Http Exception Filter
  providers: [{
    provide: APP_FILTER,
    useClass: BugsnagExceptionsFilter,
  }],
})
export class AppModule { }

Then you can inject BugsnagService. Example:

import { Controller } from '@nestjs/common';
import { BugsnagService } from '@schramautoparts/nest-bugsnag';

@Controller('cats')
export class CatsController {
  constructor(private readonly bugsnag: BugsnagService) { }
}

BugsnagService has instance property which wrap bugsnag client. So you can access it by calling:

try {
  something.risky()
} catch (e) {
    this.bugsnag.instance.notify('message');
}

Async configuration Sample

import { Module } from '@nestjs/common';
import { BugsnagModule } from '@schramautoparts/nest-bugsnag';

@Module({
  imports: [
    BugsnagModule.registerAsync({
      useFactory: (configService: ConfigService) => ({
        // options
      }),
      inject: [ConfigService],
    }),
  ],
})
export class AppModule { }

The factory might be async and is able to inject dependencies through the inject option.