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:
@ -0,0 +1,11 @@
|
||||
import { CustomException } from 'src/utils/custom-exception';
|
||||
|
||||
export class DataSourceException extends CustomException {
|
||||
constructor(message: string, code: DataSourceExceptionCode) {
|
||||
super(message, code);
|
||||
}
|
||||
}
|
||||
|
||||
export enum DataSourceExceptionCode {
|
||||
DATA_SOURCE_NOT_FOUND = 'DATA_SOURCE_NOT_FOUND',
|
||||
}
|
||||
@ -3,6 +3,11 @@ import { InjectRepository } from '@nestjs/typeorm';
|
||||
|
||||
import { FindManyOptions, Repository } from 'typeorm';
|
||||
|
||||
import {
|
||||
DataSourceException,
|
||||
DataSourceExceptionCode,
|
||||
} from 'src/engine/metadata-modules/data-source/data-source.exception';
|
||||
|
||||
import { DataSourceEntity } from './data-source.entity';
|
||||
|
||||
@Injectable()
|
||||
@ -58,10 +63,17 @@ export class DataSourceService {
|
||||
async getLastDataSourceMetadataFromWorkspaceIdOrFail(
|
||||
workspaceId: string,
|
||||
): Promise<DataSourceEntity> {
|
||||
return this.dataSourceMetadataRepository.findOneOrFail({
|
||||
where: { workspaceId },
|
||||
order: { createdAt: 'DESC' },
|
||||
});
|
||||
try {
|
||||
return this.dataSourceMetadataRepository.findOneOrFail({
|
||||
where: { workspaceId },
|
||||
order: { createdAt: 'DESC' },
|
||||
});
|
||||
} catch (error) {
|
||||
throw new DataSourceException(
|
||||
`Data source not found for workspace ${workspaceId}: ${error}`,
|
||||
DataSourceExceptionCode.DATA_SOURCE_NOT_FOUND,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async delete(workspaceId: string): Promise<void> {
|
||||
|
||||
Reference in New Issue
Block a user