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:
Thomas Trompette
2024-07-01 13:49:17 +02:00
committed by GitHub
parent 4599f43b6c
commit a15884ea0a
48 changed files with 815 additions and 199 deletions

View File

@ -1,8 +1,4 @@
import {
ForbiddenException,
Injectable,
NotFoundException,
} from '@nestjs/common';
import { Injectable } from '@nestjs/common';
import { InjectDataSource, InjectRepository } from '@nestjs/typeorm';
import isEmpty from 'lodash.isempty';
@ -27,6 +23,10 @@ import { WorkspaceDataSourceService } from 'src/engine/workspace-datasource/work
import { buildUpdateRemoteServerRawQuery } from 'src/engine/metadata-modules/remote-server/utils/build-update-remote-server-raw-query.utils';
import { validateRemoteServerType } from 'src/engine/metadata-modules/remote-server/utils/validate-remote-server-type.util';
import { FeatureFlagEntity } from 'src/engine/core-modules/feature-flag/feature-flag.entity';
import {
RemoteServerException,
RemoteServerExceptionCode,
} from 'src/engine/metadata-modules/remote-server/remote-server.exception';
@Injectable()
export class RemoteServerService<T extends RemoteServerType> {
@ -122,7 +122,10 @@ export class RemoteServerService<T extends RemoteServerType> {
);
if (!remoteServer) {
throw new NotFoundException('Remote server does not exist');
throw new RemoteServerException(
'Remote server does not exist',
RemoteServerExceptionCode.REMOTE_SERVER_NOT_FOUND,
);
}
const currentRemoteTablesForServer =
@ -132,8 +135,9 @@ export class RemoteServerService<T extends RemoteServerType> {
});
if (currentRemoteTablesForServer.length > 0) {
throw new ForbiddenException(
throw new RemoteServerException(
'Cannot update remote server with synchronized tables',
RemoteServerExceptionCode.REMOTE_SERVER_MUTATION_NOT_ALLOWED,
);
}
@ -207,7 +211,10 @@ export class RemoteServerService<T extends RemoteServerType> {
});
if (!remoteServer) {
throw new NotFoundException('Remote server does not exist');
throw new RemoteServerException(
'Remote server does not exist',
RemoteServerExceptionCode.REMOTE_SERVER_NOT_FOUND,
);
}
await this.remoteTableService.unsyncAll(workspaceId, remoteServer);