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:
@ -1,6 +1,7 @@
|
||||
import { CustomException } from 'src/utils/custom-exception';
|
||||
|
||||
export class RelationMetadataException extends CustomException {
|
||||
declare code: RelationMetadataExceptionCode;
|
||||
constructor(message: string, code: RelationMetadataExceptionCode) {
|
||||
super(message, code);
|
||||
}
|
||||
|
||||
@ -22,9 +22,17 @@ import {
|
||||
RelationMetadataException,
|
||||
RelationMetadataExceptionCode,
|
||||
} from 'src/engine/metadata-modules/relation-metadata/relation-metadata.exception';
|
||||
import { InvalidMetadataNameException } from 'src/engine/metadata-modules/utils/exceptions/invalid-metadata-name.exception';
|
||||
import { InvalidMetadataException } from 'src/engine/metadata-modules/utils/exceptions/invalid-metadata.exception';
|
||||
import { validateFieldNameAvailabilityOrThrow } from 'src/engine/metadata-modules/utils/validate-field-name-availability.utils';
|
||||
import { validateMetadataNameOrThrow } from 'src/engine/metadata-modules/utils/validate-metadata-name.utils';
|
||||
import {
|
||||
WorkspaceMetadataCacheException,
|
||||
WorkspaceMetadataCacheExceptionCode,
|
||||
} from 'src/engine/metadata-modules/workspace-metadata-cache/exceptions/workspace-metadata-cache.exception';
|
||||
import {
|
||||
WorkspaceMetadataVersionException,
|
||||
WorkspaceMetadataVersionExceptionCode,
|
||||
} from 'src/engine/metadata-modules/workspace-metadata-version/exceptions/workspace-metadata-version.exception';
|
||||
import { WorkspaceMetadataVersionService } from 'src/engine/metadata-modules/workspace-metadata-version/services/workspace-metadata-version.service';
|
||||
import { generateMigrationName } from 'src/engine/metadata-modules/workspace-migration/utils/generate-migration-name.util';
|
||||
import {
|
||||
@ -73,7 +81,7 @@ export class RelationMetadataService extends TypeOrmQueryService<RelationMetadat
|
||||
validateMetadataNameOrThrow(relationMetadataInput.fromName);
|
||||
validateMetadataNameOrThrow(relationMetadataInput.toName);
|
||||
} catch (error) {
|
||||
if (error instanceof InvalidMetadataNameException)
|
||||
if (error instanceof InvalidMetadataException)
|
||||
throw new RelationMetadataException(
|
||||
error.message,
|
||||
RelationMetadataExceptionCode.INVALID_RELATION_INPUT,
|
||||
@ -497,8 +505,9 @@ export class RelationMetadataService extends TypeOrmQueryService<RelationMetadat
|
||||
await this.workspaceCacheStorageService.getMetadataVersion(workspaceId);
|
||||
|
||||
if (!isDefined(metadataVersion)) {
|
||||
throw new NotFoundException(
|
||||
throw new WorkspaceMetadataVersionException(
|
||||
`Metadata version not found for workspace ${workspaceId}`,
|
||||
WorkspaceMetadataVersionExceptionCode.METADATA_VERSION_NOT_FOUND,
|
||||
);
|
||||
}
|
||||
|
||||
@ -509,8 +518,9 @@ export class RelationMetadataService extends TypeOrmQueryService<RelationMetadat
|
||||
);
|
||||
|
||||
if (!objectMetadataMaps) {
|
||||
throw new NotFoundException(
|
||||
throw new WorkspaceMetadataCacheException(
|
||||
`Object metadata map not found for workspace ${workspaceId} and metadata version ${metadataVersion}`,
|
||||
WorkspaceMetadataCacheExceptionCode.OBJECT_METADATA_MAP_NOT_FOUND,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -1,7 +1,5 @@
|
||||
import {
|
||||
ConflictError,
|
||||
InternalServerError,
|
||||
NotFoundError,
|
||||
UserInputError,
|
||||
} from 'src/engine/core-modules/graphql/utils/graphql-errors.util';
|
||||
import {
|
||||
@ -17,15 +15,18 @@ export const relationMetadataGraphqlApiExceptionHandler = (error: Error) => {
|
||||
|
||||
if (error instanceof RelationMetadataException) {
|
||||
switch (error.code) {
|
||||
case RelationMetadataExceptionCode.RELATION_METADATA_NOT_FOUND:
|
||||
throw new NotFoundError(error.message);
|
||||
case RelationMetadataExceptionCode.INVALID_RELATION_INPUT:
|
||||
throw new UserInputError(error.message);
|
||||
case RelationMetadataExceptionCode.RELATION_ALREADY_EXISTS:
|
||||
throw new ConflictError(error.message);
|
||||
case RelationMetadataExceptionCode.FOREIGN_KEY_NOT_FOUND:
|
||||
default:
|
||||
throw new InternalServerError(error.message);
|
||||
case RelationMetadataExceptionCode.RELATION_METADATA_NOT_FOUND:
|
||||
throw error;
|
||||
default: {
|
||||
const _exhaustiveCheck: never = error.code;
|
||||
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user