Improve sentry grouping (#12007)

This PR attemps at improving sentry grouping and filtering by 
- Using the exceptionCode as the fingerprint when the error is a
customException. For this to work in this PR we are now throwing
customExceptions instead of internalServerError deprived of their code.
They will still be converted to Internal server errors when sent back as
response
- Filtering 4xx issues where it was missing (for emailVerification
because errors were not handled, for invalid captcha and billing errors
because they are httpErrors and not graphqlErrors)

---------

Co-authored-by: Félix Malfait <felix@twenty.com>
This commit is contained in:
Marie
2025-05-14 11:00:06 +02:00
committed by GitHub
parent 6a1da5fe53
commit 9c2b88870f
57 changed files with 376 additions and 152 deletions
@@ -24,7 +24,6 @@ export enum ErrorCode {
PERSISTED_QUERY_NOT_SUPPORTED = 'PERSISTED_QUERY_NOT_SUPPORTED',
BAD_USER_INPUT = 'BAD_USER_INPUT',
NOT_FOUND = 'NOT_FOUND',
EMAIL_NOT_VERIFIED = 'EMAIL_NOT_VERIFIED',
METHOD_NOT_ALLOWED = 'METHOD_NOT_ALLOWED',
CONFLICT = 'CONFLICT',
TIMEOUT = 'TIMEOUT',
@@ -107,16 +106,16 @@ export class ValidationError extends BaseGraphQLError {
}
export class AuthenticationError extends BaseGraphQLError {
constructor(message: string) {
super(message, ErrorCode.UNAUTHENTICATED);
constructor(message: string, extensions?: Record<string, any>) {
super(message, ErrorCode.UNAUTHENTICATED, extensions);
Object.defineProperty(this, 'name', { value: 'AuthenticationError' });
}
}
export class ForbiddenError extends BaseGraphQLError {
constructor(message: string) {
super(message, ErrorCode.FORBIDDEN);
constructor(message: string, extensions?: Record<string, any>) {
super(message, ErrorCode.FORBIDDEN, extensions);
Object.defineProperty(this, 'name', { value: 'ForbiddenError' });
}
@@ -161,14 +160,6 @@ export class NotFoundError extends BaseGraphQLError {
}
}
export class EmailNotVerifiedError extends BaseGraphQLError {
constructor(message: string) {
super(message, ErrorCode.EMAIL_NOT_VERIFIED);
Object.defineProperty(this, 'name', { value: 'EmailNotVerifiedError' });
}
}
export class MethodNotAllowedError extends BaseGraphQLError {
constructor(message: string) {
super(message, ErrorCode.METHOD_NOT_ALLOWED);
@@ -1,3 +1,5 @@
import { HttpException } from '@nestjs/common';
import {
BaseGraphQLError,
ErrorCode,
@@ -12,7 +14,6 @@ export const graphQLErrorCodesToFilterOut = [
ErrorCode.TIMEOUT,
ErrorCode.CONFLICT,
ErrorCode.BAD_USER_INPUT,
ErrorCode.EMAIL_NOT_VERIFIED,
];
export const shouldCaptureException = (exception: Error): boolean => {
@@ -23,5 +24,13 @@ export const shouldCaptureException = (exception: Error): boolean => {
return false;
}
if (
exception instanceof HttpException &&
exception.getStatus() >= 400 &&
exception.getStatus() < 500
) {
return false;
}
return true;
};