Skip to content

Commit

Permalink
#150: Change ICATValidationError to raise a BadRequestError
Browse files Browse the repository at this point in the history
- An exception raised as an alternative to the database going into an invalid state will usually be due to invalid user input
- This fixes the failing test created in the previous commit
  • Loading branch information
MRichards99 committed Nov 24, 2020
1 parent 451e4d7 commit ba62e44
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions datagateway_api/common/icat/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,10 @@ def update_attributes(old_entity, new_entity):

try:
old_entity.update()
except (ICATValidationError, ICATInternalError) as e:
except ICATInternalError as e:
raise PythonICATError(e)
except ICATValidationError as e:
raise BadRequestError(e)


def get_entity_by_id(
Expand Down Expand Up @@ -474,9 +476,9 @@ def create_entities(client, entity_type, data):

try:
new_entity.create()
except (ICATValidationError, ICATInternalError) as e:
except ICATInternalError as e:
raise PythonICATError(e)
except (ICATObjectExistsError, ICATParameterError) as e:
except (ICATObjectExistsError, ICATParameterError, ICATValidationError) as e:
raise BadRequestError(e)

created_data.append(get_entity_by_id(client, entity_type, new_entity.id, True))
Expand Down

0 comments on commit ba62e44

Please sign in to comment.