@bugban/nestjs
v1.2.0
Published
Bugban SDK for NestJS — exception filter and module for automatic error reporting.
Downloads
268
Maintainers
Readme
@bugban/nestjs
Bugban error and performance monitoring for NestJS.
npm install @bugban/nestjsWhy the adapter
Nest wraps request handling in its own exception layer, so a throwing controller never reaches uncaughtException — it goes to the registered exception filter. Hooking that filter is the only way to see controller errors.
Setup
// app.module.ts
import { Module } from '@nestjs/common';
import { BugbanModule } from '@bugban/nestjs';
@Module({
imports: [
BugbanModule.forRoot({
apiKey: process.env.BUGBAN_API_KEY,
host: 'https://bugban.online',
release: process.env.APP_VERSION,
environment: process.env.NODE_ENV,
}),
],
})
export class AppModule {}// main.ts
import { NestFactory } from '@nestjs/core';
import { BugbanExceptionFilter } from '@bugban/nestjs';
import { AppModule } from './app.module';
const app = await NestFactory.create(AppModule);
app.useGlobalFilters(new BugbanExceptionFilter());
await app.listen(3000);Each report carries the HTTP method, the route pattern and the status code.
Keeping your own filter
By default the exception is rethrown so Nest's built-in filter formats the response. If you already have a filter that shapes error responses, hand it through:
app.useGlobalFilters(
new BugbanExceptionFilter((exception, host) => myFilter.catch(exception, host)),
);What counts as an error
An HttpException with a 4xx status is the app telling the client it did something wrong, not a defect — those are skipped. Everything else is reported.
Injecting the client
import { Inject, Injectable } from '@nestjs/common';
import { BUGBAN_CLIENT, capture } from '@bugban/nestjs';
@Injectable()
export class OrdersService {
constructor(@Inject(BUGBAN_CLIENT) private readonly bugban) {}
async run() {
try {
await this.work();
} catch (err) {
capture(err, { handled: true, context: { service: 'orders' } });
}
}
}Slow database queries
import { bugbanNestTypeOrmLogger } from '@bugban/nestjs';
TypeOrmModule.forRoot({ ...options, logger: bugbanNestTypeOrmLogger() });Prisma, Knex and pg hooks are available from @bugban/node, which is bundled in.
License
MIT
