From 6e22796d15621d52cef79e7fcf12d436d069803b Mon Sep 17 00:00:00 2001 From: Pranav C Date: Tue, 17 Oct 2023 19:41:46 +0000 Subject: [PATCH] chore: integrate sentry --- packages/nocodb/src/Noco.ts | 2 -- packages/nocodb/src/app.module.ts | 2 +- .../global-exception/global-exception.filter.ts | 15 +++++++++++++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/packages/nocodb/src/Noco.ts b/packages/nocodb/src/Noco.ts index 7b0ea06d9f..baf1d0fb8f 100644 --- a/packages/nocodb/src/Noco.ts +++ b/packages/nocodb/src/Noco.ts @@ -1,6 +1,4 @@ import path from 'path'; -import * as Sentry from '@sentry/node'; -import { Logger } from '@nestjs/common'; import { NestFactory } from '@nestjs/core'; import clear from 'clear'; import * as express from 'express'; diff --git a/packages/nocodb/src/app.module.ts b/packages/nocodb/src/app.module.ts index 493b9b0c9f..b36bf4988b 100644 --- a/packages/nocodb/src/app.module.ts +++ b/packages/nocodb/src/app.module.ts @@ -25,7 +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"; +import { packageInfo } from '~/utils/packageVersion'; export const ceModuleConfig = { imports: [ diff --git a/packages/nocodb/src/filters/global-exception/global-exception.filter.ts b/packages/nocodb/src/filters/global-exception/global-exception.filter.ts index ef3d2268aa..dffbdd94d2 100644 --- a/packages/nocodb/src/filters/global-exception/global-exception.filter.ts +++ b/packages/nocodb/src/filters/global-exception/global-exception.filter.ts @@ -1,7 +1,8 @@ import { Catch, Logger, NotFoundException, Optional } from '@nestjs/common'; import { InjectSentry, SentryService } from '@ntegral/nestjs-sentry'; +import { ThrottlerException } from '@nestjs/throttler'; import type { ArgumentsHost, ExceptionFilter } from '@nestjs/common'; -import type { Response } from 'express'; +import type { Request, Response } from 'express'; import { AjvError, BadRequest, @@ -25,6 +26,7 @@ export class GlobalExceptionFilter implements ExceptionFilter { catch(exception: any, host: ArgumentsHost) { const ctx = host.switchToHttp(); const response = ctx.getResponse(); + const request = ctx.getRequest(); // skip unnecessary error logging if ( @@ -37,11 +39,20 @@ export class GlobalExceptionFilter implements ExceptionFilter { exception instanceof NotFound || exception instanceof NotImplemented || exception instanceof UnprocessableEntity || - exception instanceof NotFoundException + exception instanceof NotFoundException || + exception instanceof ThrottlerException ) ) this.logger.error(exception.message, exception.stack); + if (exception instanceof ThrottlerException) { + this.logger.log( + `${exception.message}, Path : ${request.path}, Workspace ID : ${ + (request as any).ncWorkspaceId + }, Project ID : ${(request as any).ncProjectId}`, + ); + } + // API not found if (exception instanceof NotFoundException) { this.logger.debug(exception.message, exception.stack);