mirror of
https://github.com/apricote/Listory.git
synced 2026-01-13 21:21:02 +00:00
feat(api): setup optional sentry error reporting
This commit is contained in:
parent
d620c03219
commit
56db4cd2e1
5 changed files with 2201 additions and 71 deletions
27
src/main.ts
27
src/main.ts
|
|
@ -1,8 +1,26 @@
|
|||
import { ValidationPipe } from "@nestjs/common";
|
||||
import { ConfigService } from "@nestjs/config";
|
||||
import { NestFactory } from "@nestjs/core";
|
||||
import { NestExpressApplication } from "@nestjs/platform-express";
|
||||
import { DocumentBuilder, SwaggerModule } from "@nestjs/swagger";
|
||||
import { AppModule } from "./app.module";
|
||||
import { ValidationPipe } from "@nestjs/common";
|
||||
import * as Sentry from "@sentry/node";
|
||||
import { RavenInterceptor } from "nest-raven";
|
||||
|
||||
function setupSentry(
|
||||
app: NestExpressApplication,
|
||||
configService: ConfigService
|
||||
) {
|
||||
Sentry.init({
|
||||
dsn: configService.get<string>("SENTRY_DSN"),
|
||||
integrations: [
|
||||
new Sentry.Integrations.OnUncaughtException(),
|
||||
new Sentry.Integrations.OnUnhandledRejection(),
|
||||
],
|
||||
});
|
||||
|
||||
app.useGlobalInterceptors(new RavenInterceptor());
|
||||
}
|
||||
|
||||
async function bootstrap() {
|
||||
const app = await NestFactory.create<NestExpressApplication>(AppModule);
|
||||
|
|
@ -14,6 +32,12 @@ async function bootstrap() {
|
|||
);
|
||||
app.enableShutdownHooks();
|
||||
|
||||
const configService = app.get<ConfigService>(ConfigService);
|
||||
|
||||
if (configService.get<boolean>("SENTRY_ENABLED")) {
|
||||
setupSentry(app, configService);
|
||||
}
|
||||
|
||||
// Setup API Docs
|
||||
const options = new DocumentBuilder()
|
||||
.setTitle("Listory")
|
||||
|
|
@ -29,4 +53,5 @@ async function bootstrap() {
|
|||
|
||||
await app.listen(3000);
|
||||
}
|
||||
|
||||
bootstrap();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue