fix: properly handle errors on event creation/update

pull/307/head
Raphaël Vinot 2018-11-28 17:34:38 +01:00
parent 1343432e32
commit de118795ce
2 changed files with 7 additions and 2 deletions

View File

@ -97,6 +97,8 @@ class ExpandedPyMISP(PyMISP):
created_event = super().add_event(event)
if isinstance(created_event, str):
raise NewEventError(f'Unexpected response from server: {created_event}')
elif 'errors' in created_event:
return created_event
e = MISPEvent()
e.load(created_event)
return e
@ -105,6 +107,8 @@ class ExpandedPyMISP(PyMISP):
updated_event = super().update_event(event.uuid, event)
if isinstance(updated_event, str):
raise UpdateEventError(f'Unexpected response from server: {updated_event}')
elif 'errors' in updated_event:
return updated_event
e = MISPEvent()
e.load(updated_event)
return e
@ -113,6 +117,8 @@ class ExpandedPyMISP(PyMISP):
updated_attribute = super().update_attribute(attribute.uuid, attribute)
if isinstance(updated_attribute, str):
raise UpdateAttributeError(f'Unexpected response from server: {updated_attribute}')
elif 'errors' in updated_attribute:
return updated_attribute
a = MISPAttribute()
a.from_dict(**updated_attribute)
return a

View File

@ -469,8 +469,7 @@ class MISPEvent(AbstractMISP):
'attribute_count' in event.get('Event') and
event.get('Event').get('attribute_count') is None):
event['Event']['attribute_count'] = '0'
e = event.get('Event')
self.from_dict(**e)
self.from_dict(**event['Event'])
if validate:
jsonschema.validate(json.loads(self.to_json()), self.__json_schema)