Skip to content

Commit

Permalink
Handle ValueError on setstate on closed event
Browse files Browse the repository at this point in the history
  • Loading branch information
hmpf committed Dec 6, 2023
1 parent 9e45585 commit 6188784
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")

Check warning on line 504 in src/zinolib/controllers/zino1.py

View check run for this annotation

Codecov / codecov/patch

src/zinolib/controllers/zino1.py#L500-L504

Added lines #L500 - L504 were not covered by tests
else:
raise

Check warning on line 506 in src/zinolib/controllers/zino1.py

View check run for this annotation

Codecov / codecov/patch

src/zinolib/controllers/zino1.py#L506

Added line #L506 was not covered by tests
if success:
event = self.get_updated_event_for_id(event_id)
self._set_event(event)
Expand Down

0 comments on commit 6188784

Please sign in to comment.