From 6188784b466a0a984a4c1d70d66ec105cf8a9d41 Mon Sep 17 00:00:00 2001 From: Hanne Moa Date: Tue, 5 Dec 2023 12:58:03 +0100 Subject: [PATCH] Handle ValueError on setstate on closed event --- src/zinolib/controllers/zino1.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/zinolib/controllers/zino1.py b/src/zinolib/controllers/zino1.py index 60604df..8dbfa2d 100644 --- a/src/zinolib/controllers/zino1.py +++ b/src/zinolib/controllers/zino1.py @@ -106,6 +106,10 @@ class RetryError(Zino1Error): pass +class EventClosedError(Zino1Error): + pass + + def convert_timestamp(timestamp: int) -> datetime: return datetime.fromtimestamp(timestamp, timezone.utc) @@ -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)