Skip to content

Commit

Permalink
Merge pull request #43 from hmpf/valueerror-setstate
Browse files Browse the repository at this point in the history
Handle ValueError on setstate on closed event
  • Loading branch information
hmpf authored Jan 10, 2024
2 parents 9e45585 + 6188784 commit eeef0ff
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/zinolib/controllers/zino1.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ class RetryError(Zino1Error):
pass


class EventClosedError(Zino1Error):
pass


def convert_timestamp(timestamp: int) -> datetime:
return datetime.fromtimestamp(timestamp, timezone.utc)

Expand Down Expand Up @@ -493,7 +497,13 @@ def get_updated_event_for_id(self, event_id):
def change_admin_state_for_id(self, event_id, admin_state: AdmState) -> Optional[Event]:
self._verify_session()
event = self._get_event(event_id)
success = self._event_adapter.set_admin_state(self.session.request, event, admin_state)
try:
success = self._event_adapter.set_admin_state(self.session.request, event, admin_state)
except ValueError as e:
if 'reopen' in str(e):
raise EventClosedError("Cannot set state on closed event")
else:
raise
if success:
event = self.get_updated_event_for_id(event_id)
self._set_event(event)
Expand Down

0 comments on commit eeef0ff

Please sign in to comment.