Skip to content

Commit

Permalink
add try except on sending a new msg with meme
Browse files Browse the repository at this point in the history
  • Loading branch information
ohld committed Jun 18, 2024
1 parent 1092a2d commit 81d3ccc
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/tgbot/senders/next_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
Message,
Update,
)
from telegram.error import BadRequest

from src.recommendations import meme_queue
from src.recommendations.service import (
Expand Down Expand Up @@ -86,9 +87,14 @@ async def next_message(
prev_reaction_id is None or Reaction(prev_reaction_id).is_positive
)
if not send_new_message and prev_update_can_be_edited_with_media(prev_update):
msg = await edit_last_message_with_meme(
prev_update.callback_query.message, meme, reply_markup
)
try:
msg = await edit_last_message_with_meme(
prev_update.callback_query.message, meme, reply_markup
)
except BadRequest as e:
logging.error(f"Failed to edit message: {e}")
msg = await send_new_message_with_meme(bot, user_id, meme, reply_markup)

else:
msg = await send_new_message_with_meme(bot, user_id, meme, reply_markup)

Expand Down

0 comments on commit 81d3ccc

Please sign in to comment.