Fix metadata exception handler #2 (#3357)

This commit is contained in:
Weiko
2024-01-10 17:02:54 +01:00
committed by GitHub
parent 4f9ea78258
commit 22047fa2bf
9 changed files with 17 additions and 24 deletions

View File

@@ -1,7 +1,5 @@
import { HttpException } from '@nestjs/common';
import { TypeORMError } from 'typeorm';
import {
AuthenticationError,
BaseGraphQLError,
@@ -29,12 +27,10 @@ export const handleException = (
exception: Error,
exceptionHandlerService: ExceptionHandlerService,
): void => {
if (
exception instanceof TypeORMError ||
(exception instanceof HttpException && exception.getStatus() >= 500)
) {
exceptionHandlerService.captureException(exception);
if (exception instanceof HttpException && exception.getStatus() < 500) {
return;
}
exceptionHandlerService.captureException(exception);
};
export const convertExceptionToGraphQLError = (

View File

@@ -11,7 +11,7 @@ export class ExceptionHandlerSentryDriver
{
constructor(options: ExceptionHandlerSentryDriverFactoryOptions['options']) {
Sentry.init({
dsn: options.dns,
dsn: options.dsn,
integrations: [
// enable HTTP calls tracing
new Sentry.Integrations.Http({ tracing: true }),

View File

@@ -25,7 +25,7 @@ export const exceptionHandlerModuleFactory = async (
return {
type: ExceptionHandlerDriver.Sentry,
options: {
dns: environmentService.getSentryDSN() ?? '',
dsn: environmentService.getSentryDSN() ?? '',
serverInstance: adapterHost.httpAdapter?.getInstance(),
debug: environmentService.isDebugMode(),
},

View File

@@ -8,7 +8,7 @@ export enum ExceptionHandlerDriver {
export interface ExceptionHandlerSentryDriverFactoryOptions {
type: ExceptionHandlerDriver.Sentry;
options: {
dns: string;
dsn: string;
serverInstance?: Router;
debug?: boolean;
};

View File

@@ -19,14 +19,10 @@ export class FieldMetadataResolver {
@Args('input') input: CreateOneFieldMetadataInput,
@AuthWorkspace() { id: workspaceId }: Workspace,
) {
try {
return this.fieldMetadataService.createOne({
...input.field,
workspaceId,
});
} catch (error) {
console.log(error);
}
return this.fieldMetadataService.createOne({
...input.field,
workspaceId,
});
}
@Mutation(() => FieldMetadataDTO)

View File

@@ -56,7 +56,7 @@ export class FieldMetadataService extends TypeOrmQueryService<FieldMetadataEntit
);
if (!objectMetadata) {
throw new Error('Object does not exist');
throw new NotFoundException('Object does not exist');
}
const fieldAlreadyExists = await this.fieldMetadataRepository.findOne({

View File

@@ -24,9 +24,9 @@ export const metadataModuleFactory = async (
error.originalError,
exceptionHandlerService,
);
} else {
return maskError(error, message, isDev);
}
return maskError(error, message, isDev);
},
},
});

View File

@@ -6,6 +6,7 @@ import { YogaDriverConfig, YogaDriver } from '@graphql-yoga/nestjs';
import { WorkspaceMigrationRunnerModule } from 'src/workspace/workspace-migration-runner/workspace-migration-runner.module';
import { WorkspaceMigrationModule } from 'src/metadata/workspace-migration/workspace-migration.module';
import { metadataModuleFactory } from 'src/metadata/metadata.module-factory';
import { ExceptionHandlerService } from 'src/integrations/exception-handler/exception-handler.service';
import { DataSourceModule } from './data-source/data-source.module';
import { FieldMetadataModule } from './field-metadata/field-metadata.module';
@@ -15,7 +16,7 @@ import { RelationMetadataModule } from './relation-metadata/relation-metadata.mo
imports: [
GraphQLModule.forRootAsync<YogaDriverConfig>({
driver: YogaDriver,
imports: [],
inject: [ExceptionHandlerService],
useFactory: metadataModuleFactory,
}),
DataSourceModule,

View File

@@ -1,4 +1,4 @@
import { Injectable } from '@nestjs/common';
import { BadRequestException, Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { FindManyOptions, FindOneOptions, Repository } from 'typeorm';
@@ -59,7 +59,7 @@ export class ObjectMetadataService extends TypeOrmQueryService<ObjectMetadataEnt
objectMetadataInput.nameSingular.toLowerCase() ===
objectMetadataInput.namePlural.toLowerCase()
) {
throw new Error(
throw new BadRequestException(
'The singular and plural name cannot be the same for an object',
);
}