Skip to content

Commit

Permalink
#136: Catch exception when an attribute cannot be found
Browse files Browse the repository at this point in the history
- API now returns a 400 with a message to the user
  • Loading branch information
MRichards99 committed Jul 22, 2020
1 parent 785adde commit cac1003
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions common/python_icat_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,11 @@ def update_attributes(object, dictionary):
allow an attribute to be edited (e.g. modId & modTime)
"""
for key in dictionary:
original_data_attribute = getattr(object, key)
dictionary[key] = str_to_date_object(original_data_attribute, dictionary[key])
try:
original_data_attribute = getattr(object, key)
dictionary[key] = str_to_date_object(original_data_attribute, dictionary[key])
except AttributeError:
raise BadRequestError(f"Bad request made, cannot find attribute '{key}' within the {object.BeanName} entity")

try:
setattr(object, key, dictionary[key])
Expand Down

0 comments on commit cac1003

Please sign in to comment.