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:
+8
-3
@@ -1,9 +1,11 @@
|
||||
import { BadRequestException } from '@nestjs/common/exceptions';
|
||||
|
||||
import { singular } from 'pluralize';
|
||||
import { DataSource } from 'typeorm';
|
||||
|
||||
import { camelCase } from 'src/utils/camel-case';
|
||||
import {
|
||||
RemoteTableException,
|
||||
RemoteTableExceptionCode,
|
||||
} from 'src/engine/metadata-modules/remote-server/remote-table/remote-table.exception';
|
||||
|
||||
const MAX_SUFFIX = 10;
|
||||
|
||||
@@ -55,5 +57,8 @@ export const getRemoteTableLocalName = async (
|
||||
}
|
||||
}
|
||||
|
||||
throw new BadRequestException('Table name is already taken.');
|
||||
throw new RemoteTableException(
|
||||
'Table name is already taken',
|
||||
RemoteTableExceptionCode.INVALID_REMOTE_TABLE_INPUT,
|
||||
);
|
||||
};
|
||||
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
import {
|
||||
RemoteTableException,
|
||||
RemoteTableExceptionCode,
|
||||
} from 'src/engine/metadata-modules/remote-server/remote-table/remote-table.exception';
|
||||
import {
|
||||
UserInputError,
|
||||
ConflictError,
|
||||
InternalServerError,
|
||||
NotFoundError,
|
||||
} from 'src/engine/utils/graphql-errors.util';
|
||||
|
||||
export const remoteTableGraphqlApiExceptionHandler = (error: Error) => {
|
||||
if (error instanceof RemoteTableException) {
|
||||
switch (error.code) {
|
||||
case RemoteTableExceptionCode.REMOTE_TABLE_NOT_FOUND:
|
||||
case RemoteTableExceptionCode.NO_OBJECT_METADATA_FOUND:
|
||||
case RemoteTableExceptionCode.NO_FOREIGN_TABLES_FOUND:
|
||||
case RemoteTableExceptionCode.NO_FIELD_METADATA_FOUND:
|
||||
throw new NotFoundError(error.message);
|
||||
case RemoteTableExceptionCode.INVALID_REMOTE_TABLE_INPUT:
|
||||
throw new UserInputError(error.message);
|
||||
case RemoteTableExceptionCode.REMOTE_TABLE_ALREADY_EXISTS:
|
||||
throw new ConflictError(error.message);
|
||||
default:
|
||||
throw new InternalServerError(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
throw error;
|
||||
};
|
||||
Reference in New Issue
Block a user