Browse Source

chore: integrate sentry

pull/6718/head
Pranav C 1 year ago
parent
commit
6e22796d15
  1. 2
      packages/nocodb/src/Noco.ts
  2. 2
      packages/nocodb/src/app.module.ts
  3. 15
      packages/nocodb/src/filters/global-exception/global-exception.filter.ts

2
packages/nocodb/src/Noco.ts

@ -1,6 +1,4 @@
import path from 'path'; import path from 'path';
import * as Sentry from '@sentry/node';
import { Logger } from '@nestjs/common';
import { NestFactory } from '@nestjs/core'; import { NestFactory } from '@nestjs/core';
import clear from 'clear'; import clear from 'clear';
import * as express from 'express'; import * as express from 'express';

2
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 { BasicStrategy } from '~/strategies/basic.strategy/basic.strategy';
import { UsersModule } from '~/modules/users/users.module'; import { UsersModule } from '~/modules/users/users.module';
import { AuthModule } from '~/modules/auth/auth.module'; import { AuthModule } from '~/modules/auth/auth.module';
import {packageInfo} from "~/utils/packageVersion"; import { packageInfo } from '~/utils/packageVersion';
export const ceModuleConfig = { export const ceModuleConfig = {
imports: [ imports: [

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

@ -1,7 +1,8 @@
import { Catch, Logger, NotFoundException, Optional } from '@nestjs/common'; import { Catch, Logger, NotFoundException, Optional } from '@nestjs/common';
import { InjectSentry, SentryService } from '@ntegral/nestjs-sentry'; import { InjectSentry, SentryService } from '@ntegral/nestjs-sentry';
import { ThrottlerException } from '@nestjs/throttler';
import type { ArgumentsHost, ExceptionFilter } from '@nestjs/common'; import type { ArgumentsHost, ExceptionFilter } from '@nestjs/common';
import type { Response } from 'express'; import type { Request, Response } from 'express';
import { import {
AjvError, AjvError,
BadRequest, BadRequest,
@ -25,6 +26,7 @@ export class GlobalExceptionFilter implements ExceptionFilter {
catch(exception: any, host: ArgumentsHost) { catch(exception: any, host: ArgumentsHost) {
const ctx = host.switchToHttp(); const ctx = host.switchToHttp();
const response = ctx.getResponse<Response>(); const response = ctx.getResponse<Response>();
const request = ctx.getRequest<Request>();
// skip unnecessary error logging // skip unnecessary error logging
if ( if (
@ -37,11 +39,20 @@ export class GlobalExceptionFilter implements ExceptionFilter {
exception instanceof NotFound || exception instanceof NotFound ||
exception instanceof NotImplemented || exception instanceof NotImplemented ||
exception instanceof UnprocessableEntity || exception instanceof UnprocessableEntity ||
exception instanceof NotFoundException exception instanceof NotFoundException ||
exception instanceof ThrottlerException
) )
) )
this.logger.error(exception.message, exception.stack); 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 // API not found
if (exception instanceof NotFoundException) { if (exception instanceof NotFoundException) {
this.logger.debug(exception.message, exception.stack); this.logger.debug(exception.message, exception.stack);

Loading…
Cancel
Save