diff --git a/aw_client/client.py b/aw_client/client.py index ef0ea84..7ef6d33 100644 --- a/aw_client/client.py +++ b/aw_client/client.py @@ -139,10 +139,16 @@ def get_event( self, bucket_id: str, event_id: int, - ) -> Event: + ) -> Optional[Event]: endpoint = f"buckets/{bucket_id}/events/{event_id}" - event = self._get(endpoint).json() - return Event(**event) + try: + event = self._get(endpoint).json() + return Event(**event) + except req.exceptions.HTTPError as e: + if e.response.status_code == 404: + return None + else: + raise def delete_event( self, diff --git a/tests/test_client.py b/tests/test_client.py index a059062..3db927b 100755 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -79,8 +79,7 @@ def test_full(): # Delete single event client.delete_event(bucket_name, fetched_events[1].id) - with pytest.raises(ValueError): - client.get_event(bucket_name, fetched_events[1].id) + assert client.get_event(bucket_name, fetched_events[1].id) is None # Test exception raising with pytest.raises(ValueError):