Add exceptions for metadata modules (#6070)
Class exception for each metadata module + handler to map on graphql error TODO left : - find a way to call handler on auto-resolvers nestjs query (probably interceptors) - discuss what should be done for pre-hooks errors - discuss what should be done for Unauthorized exception
This commit is contained in:
@ -11,6 +11,7 @@ import { RemoteServerDTO } from 'src/engine/metadata-modules/remote-server/dtos/
|
||||
import { UpdateRemoteServerInput } from 'src/engine/metadata-modules/remote-server/dtos/update-remote-server.input';
|
||||
import { RemoteServerType } from 'src/engine/metadata-modules/remote-server/remote-server.entity';
|
||||
import { RemoteServerService } from 'src/engine/metadata-modules/remote-server/remote-server.service';
|
||||
import { remoteServerGraphqlApiExceptionHandler } from 'src/engine/metadata-modules/remote-server/utils/remote-server-graphql-api-exception-handler.util';
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Resolver()
|
||||
@ -24,7 +25,11 @@ export class RemoteServerResolver {
|
||||
@Args('input') input: CreateRemoteServerInput<RemoteServerType>,
|
||||
@AuthWorkspace() { id: workspaceId }: Workspace,
|
||||
) {
|
||||
return this.remoteServerService.createOneRemoteServer(input, workspaceId);
|
||||
try {
|
||||
return this.remoteServerService.createOneRemoteServer(input, workspaceId);
|
||||
} catch (error) {
|
||||
remoteServerGraphqlApiExceptionHandler(error);
|
||||
}
|
||||
}
|
||||
|
||||
@Mutation(() => RemoteServerDTO)
|
||||
@ -32,7 +37,11 @@ export class RemoteServerResolver {
|
||||
@Args('input') input: UpdateRemoteServerInput<RemoteServerType>,
|
||||
@AuthWorkspace() { id: workspaceId }: Workspace,
|
||||
) {
|
||||
return this.remoteServerService.updateOneRemoteServer(input, workspaceId);
|
||||
try {
|
||||
return this.remoteServerService.updateOneRemoteServer(input, workspaceId);
|
||||
} catch (error) {
|
||||
remoteServerGraphqlApiExceptionHandler(error);
|
||||
}
|
||||
}
|
||||
|
||||
@Mutation(() => RemoteServerDTO)
|
||||
@ -40,7 +49,11 @@ export class RemoteServerResolver {
|
||||
@Args('input') { id }: RemoteServerIdInput,
|
||||
@AuthWorkspace() { id: workspaceId }: Workspace,
|
||||
) {
|
||||
return this.remoteServerService.deleteOneRemoteServer(id, workspaceId);
|
||||
try {
|
||||
return this.remoteServerService.deleteOneRemoteServer(id, workspaceId);
|
||||
} catch (error) {
|
||||
remoteServerGraphqlApiExceptionHandler(error);
|
||||
}
|
||||
}
|
||||
|
||||
@Query(() => RemoteServerDTO)
|
||||
@ -48,7 +61,14 @@ export class RemoteServerResolver {
|
||||
@Args('input') { id }: RemoteServerIdInput,
|
||||
@AuthWorkspace() { id: workspaceId }: Workspace,
|
||||
) {
|
||||
return this.remoteServerService.findOneByIdWithinWorkspace(id, workspaceId);
|
||||
try {
|
||||
return this.remoteServerService.findOneByIdWithinWorkspace(
|
||||
id,
|
||||
workspaceId,
|
||||
);
|
||||
} catch (error) {
|
||||
remoteServerGraphqlApiExceptionHandler(error);
|
||||
}
|
||||
}
|
||||
|
||||
@Query(() => [RemoteServerDTO])
|
||||
@ -57,9 +77,13 @@ export class RemoteServerResolver {
|
||||
{ foreignDataWrapperType }: RemoteServerTypeInput<RemoteServerType>,
|
||||
@AuthWorkspace() { id: workspaceId }: Workspace,
|
||||
) {
|
||||
return this.remoteServerService.findManyByTypeWithinWorkspace(
|
||||
foreignDataWrapperType,
|
||||
workspaceId,
|
||||
);
|
||||
try {
|
||||
return this.remoteServerService.findManyByTypeWithinWorkspace(
|
||||
foreignDataWrapperType,
|
||||
workspaceId,
|
||||
);
|
||||
} catch (error) {
|
||||
remoteServerGraphqlApiExceptionHandler(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user