Skip to content

Commit

Permalink
feat: handle exceptions on context send
Browse files Browse the repository at this point in the history
  • Loading branch information
jrriehl committed Aug 30, 2023
1 parent 266a4f7 commit 4ac5c1a
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions python/src/uagents/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,18 @@ async def send_raw(
env.encode_payload(json_message)
env.sign(self._identity)

async with aiohttp.ClientSession() as session:
async with session.post(
endpoint, headers={"content-type": "application/json"}, data=env.json()
) as resp:
success = resp.status == 200
try:
async with aiohttp.ClientSession() as session:
async with session.post(
endpoint,
headers={"content-type": "application/json"},
data=env.json(),
) as resp:
success = resp.status == 200
except aiohttp.ClientConnectorError as ex:
self._logger.exception(f"Failed to connect to {endpoint}: {ex}")
except Exception as ex:
self._logger.exception(f"Failed to send message to {destination}: {ex}")

if not success:
self._logger.exception(
Expand Down

0 comments on commit 4ac5c1a

Please sign in to comment.