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:
@ -18,6 +18,7 @@ import {
|
||||
TimeoutError,
|
||||
ValidationError,
|
||||
} from 'src/engine/core-modules/graphql/utils/graphql-errors.util';
|
||||
import { CustomException } from 'src/utils/custom-exception';
|
||||
|
||||
const graphQLPredefinedExceptions = {
|
||||
400: ValidationError,
|
||||
@ -46,44 +47,63 @@ export const handleExceptionAndConvertToGraphQLError = (
|
||||
user?: ExceptionHandlerUser,
|
||||
workspace?: ExceptionHandlerWorkspace,
|
||||
): BaseGraphQLError => {
|
||||
handleException(exception, exceptionHandlerService, user, workspace);
|
||||
handleException({
|
||||
exception,
|
||||
exceptionHandlerService,
|
||||
user,
|
||||
workspace,
|
||||
});
|
||||
|
||||
return convertExceptionToGraphQLError(exception);
|
||||
};
|
||||
|
||||
export const shouldFilterException = (exception: Error): boolean => {
|
||||
export const shouldCaptureException = (
|
||||
exception: Error,
|
||||
statusCode?: number,
|
||||
): boolean => {
|
||||
if (
|
||||
exception instanceof GraphQLError &&
|
||||
(exception?.extensions?.http?.status ?? 500) < 500
|
||||
) {
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (
|
||||
exception instanceof BaseGraphQLError &&
|
||||
graphQLErrorCodesToFilter.includes(exception?.extensions?.code)
|
||||
) {
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (exception instanceof HttpException && exception.getStatus() < 500) {
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
if (statusCode && statusCode < 500) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
export const handleException = (
|
||||
exception: Error,
|
||||
exceptionHandlerService: ExceptionHandlerService,
|
||||
user?: ExceptionHandlerUser,
|
||||
workspace?: ExceptionHandlerWorkspace,
|
||||
): void => {
|
||||
if (shouldFilterException(exception)) {
|
||||
return;
|
||||
export const handleException = <T extends Error | CustomException>({
|
||||
exception,
|
||||
exceptionHandlerService,
|
||||
user,
|
||||
workspace,
|
||||
statusCode,
|
||||
}: {
|
||||
exception: T;
|
||||
exceptionHandlerService: ExceptionHandlerService;
|
||||
user?: ExceptionHandlerUser;
|
||||
workspace?: ExceptionHandlerWorkspace;
|
||||
statusCode?: number;
|
||||
}): T => {
|
||||
if (shouldCaptureException(exception, statusCode)) {
|
||||
exceptionHandlerService.captureExceptions([exception], { user, workspace });
|
||||
}
|
||||
|
||||
exceptionHandlerService.captureExceptions([exception], { user, workspace });
|
||||
return exception;
|
||||
};
|
||||
|
||||
export const convertExceptionToGraphQLError = (
|
||||
|
||||
Reference in New Issue
Block a user