Improve sentry filtering and grouping (#12071)

Follow-up on https://github.com/twentyhq/twenty/pull/12007

In this PR

- adding a filter on HttpExceptionHandlerService to filter out 4xx
errors from driver handling (as we do for graphQL errors: see
useGraphQLErrorHandler hook - only filteredIssues are sent to`
exceptionHandlerService.captureExceptions()`.)
- grouping together more missing metadata issues
- attempting to use error codes as issues names in sentry to improve UI;
for now it says "Error" all the time
This commit is contained in:
Marie
2025-05-16 11:35:48 +02:00
committed by GitHub
parent 4d303a61d1
commit dc4bcc3049
19 changed files with 145 additions and 120 deletions

View File

@ -3,9 +3,10 @@ import { Injectable } from '@nestjs/common';
import { Request, Response } from 'express';
import { isDefined } from 'twenty-shared/utils';
import { AuthExceptionCode } from 'src/engine/core-modules/auth/auth.exception';
import { AuthException } from 'src/engine/core-modules/auth/auth.exception';
import { AccessTokenService } from 'src/engine/core-modules/auth/token/services/access-token.service';
import { AuthContext } from 'src/engine/core-modules/auth/types/auth-context.type';
import { getAuthExceptionRestStatus } from 'src/engine/core-modules/auth/utils/get-auth-exception-rest-status.util';
import { ExceptionHandlerService } from 'src/engine/core-modules/exception-handler/exception-handler.service';
import { ErrorCode } from 'src/engine/core-modules/graphql/utils/graphql-errors.util';
import { JwtWrapperService } from 'src/engine/core-modules/jwt/services/jwt-wrapper.service';
@ -53,11 +54,15 @@ export class MiddlewareService {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
public writeRestResponseOnExceptionCaught(res: Response, error: any) {
// capture and handle custom exceptions
handleException(error as CustomException, this.exceptionHandlerService);
const statusCode = this.getStatus(error);
// capture and handle custom exceptions
handleException({
exception: error as CustomException,
exceptionHandlerService: this.exceptionHandlerService,
statusCode,
});
res.writeHead(statusCode, { 'Content-Type': 'application/json' });
res.write(
JSON.stringify({
@ -158,13 +163,8 @@ export class MiddlewareService {
return error.status;
}
if (error instanceof CustomException) {
switch (error.code) {
case AuthExceptionCode.UNAUTHENTICATED:
return 401;
default:
return 400;
}
if (error instanceof AuthException) {
return getAuthExceptionRestStatus(error);
}
return 500;