Browse Source

fix: correction in sentry integration

pull/6718/head
Pranav C 1 year ago
parent
commit
9149c5b28f
  1. 34
      packages/nocodb/src/Noco.ts
  2. 13
      packages/nocodb/src/app.module.ts
  3. 9
      packages/nocodb/src/filters/global-exception/global-exception.filter.ts

34
packages/nocodb/src/Noco.ts

@ -121,7 +121,7 @@ export default class Noco {
nestApp.use(requestIp.mw());
nestApp.use(cookieParser());
this.initSentry(nestApp);
// this.initSentry(nestApp);
nestApp.useWebSocketAdapter(new IoAdapter(httpServer));
@ -139,7 +139,7 @@ export default class Noco {
server.get('/', (_req, res) => res.redirect(dashboardPath));
}
this.initSentryErrorHandler(server);
// this.initSentryErrorHandler(server);
return nestApp.getHttpAdapter().getInstance();
}
@ -189,19 +189,19 @@ export default class Noco {
}
process.env.NC_SERVER_UUID = serverId;
}
private static initSentryErrorHandler(router) {
if (process.env.NC_SENTRY_DSN) {
router.use(Sentry.Handlers.errorHandler());
}
}
private static initSentry(router) {
if (process.env.NC_SENTRY_DSN) {
Sentry.init({ dsn: process.env.NC_SENTRY_DSN });
// The request handler must be the first middleware on the app
router.use(Sentry.Handlers.requestHandler());
}
}
//
// private static initSentryErrorHandler(router) {
// if (process.env.NC_SENTRY_DSN) {
// router.use(Sentry.Handlers.errorHandler());
// }
// }
//
// private static initSentry(router) {
// if (process.env.NC_SENTRY_DSN) {
// Sentry.init({ dsn: process.env.NC_SENTRY_DSN });
//
// // The request handler must be the first middleware on the app
// router.use(Sentry.Handlers.requestHandler());
// }
// }
}

13
packages/nocodb/src/app.module.ts

@ -3,6 +3,7 @@ import { APP_FILTER, APP_GUARD } from '@nestjs/core';
// @ts-ignore
import { ConfigModule } from '@nestjs/config';
import { EventEmitterModule as NestJsEventEmitter } from '@nestjs/event-emitter';
import { SentryModule } from '@ntegral/nestjs-sentry';
import type { MiddlewareConsumer } from '@nestjs/common';
import { GlobalExceptionFilter } from '~/filters/global-exception/global-exception.filter';
import { GlobalMiddleware } from '~/middlewares/global/global.middleware';
@ -24,6 +25,7 @@ import { HookHandlerService } from '~/services/hook-handler.service';
import { BasicStrategy } from '~/strategies/basic.strategy/basic.strategy';
import { UsersModule } from '~/modules/users/users.module';
import { AuthModule } from '~/modules/auth/auth.module';
import {packageInfo} from "~/utils/packageVersion";
export const ceModuleConfig = {
imports: [
@ -39,6 +41,17 @@ export const ceModuleConfig = {
load: [() => appConfig],
isGlobal: true,
}),
...(process.env.NC_SENTRY_DSN
? [
SentryModule.forRoot({
dsn: process.env.NC_SENTRY_DSN,
debug: false,
environment: process.env.NODE_ENV,
release: packageInfo.version, // must create a release in sentry.io dashboard
logLevels: ['debug'], //based on sentry.io loglevel //
}),
]
: []),
],
providers: [
AuthService,

9
packages/nocodb/src/filters/global-exception/global-exception.filter.ts

@ -1,4 +1,5 @@
import { Catch, Logger, NotFoundException } from '@nestjs/common';
import { Catch, Logger, NotFoundException, Optional } from '@nestjs/common';
import { InjectSentry, SentryService } from '@ntegral/nestjs-sentry';
import type { ArgumentsHost, ExceptionFilter } from '@nestjs/common';
import type { Response } from 'express';
import {
@ -15,6 +16,10 @@ import {
@Catch()
export class GlobalExceptionFilter implements ExceptionFilter {
constructor(
@Optional() @InjectSentry() private readonly client: SentryService,
) {}
private logger = new Logger(GlobalExceptionFilter.name);
catch(exception: any, host: ArgumentsHost) {
@ -90,6 +95,8 @@ export class GlobalExceptionFilter implements ExceptionFilter {
if (exception.getStatus?.()) {
response.status(exception.getStatus()).json(exception.getResponse());
} else {
this.client?.instance().captureException(exception);
// todo: change the response code
response.status(400).json({
msg: exception.message,

Loading…
Cancel
Save