Skip to content

Commit

Permalink
fix: fixed behavior when fetching single event that doesn't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikBjare committed Mar 3, 2022
1 parent cfa7e03 commit 0209b8a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
12 changes: 9 additions & 3 deletions aw_client/client.py
Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions tests/test_client.py
Expand Up @@ -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):
Expand Down

0 comments on commit 0209b8a

Please sign in to comment.