Skip to content

Commit

Permalink
fix error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
wizzdom committed Jan 16, 2025
1 parent 43ff3fd commit 7eed0f0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
10 changes: 8 additions & 2 deletions src/extensions/action_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,15 @@ async def get_action_items(

try:
content = await get_md_content(url, aiohttp_client)
except Exception as e:
except aiohttp.ClientResponseError as e:
await ctx.respond(
f"❌ {e}",
f"❌ **Error**: {e}",
flags=hikari.MessageFlag.EPHEMERAL,
)
return
except ValueError as e:
await ctx.respond(
f"❌ **Error**: {e}",
flags=hikari.MessageFlag.EPHEMERAL,
)
return
Expand Down
14 changes: 10 additions & 4 deletions src/extensions/agenda.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,15 @@ async def gen_agenda(

try:
content = await get_md_content(url, aiohttp_client)
except Exception as e:
except aiohttp.ClientResponseError as e:
await ctx.respond(
f"❌ {e}",
f"❌ **Error**: {e}",
flags=hikari.MessageFlag.EPHEMERAL,
)
return
except ValueError as e:
await ctx.respond(
f"❌ **Error**: {e}",
flags=hikari.MessageFlag.EPHEMERAL,
)
return
Expand All @@ -116,9 +122,9 @@ async def gen_agenda(

try:
new_agenda_url = await post_new_md_content(modified_content, aiohttp_client)
except Exception as e:
except aiohttp.ClientResponseError as e:
await ctx.respond(
f"❌ {e}",
f"❌ **Error**: {e}",
flags=hikari.MessageFlag.EPHEMERAL,
)
return
Expand Down
11 changes: 2 additions & 9 deletions src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ async def get_md_content(url: str, aiohttp_client: aiohttp.ClientSession) -> str
f"{parsed_url.scheme}://{parsed_url.hostname}{parsed_url.path}/download"
)
async with aiohttp_client.get(request_url) as response:
if response.status != 200:
raise Exception(
f"Failed to fetch the minutes. Status code: `{response.status}`"
)
response.raise_for_status()
return await response.text()


Expand All @@ -58,11 +55,7 @@ async def post_new_md_content(
headers=post_headers,
data=content,
) as response:
if response.status != 200:
raise Exception(
f"Failed to generate the agenda. Status code: `{response.status}`"
)
return None
response.raise_for_status()

return str(response.url)

Expand Down

0 comments on commit 7eed0f0

Please sign in to comment.