Skip to content

Commit dc68720

Browse files
committed
feat: enhance error handling for dismissed join requests and deactivated users
1 parent 8e2f22f commit dc68720

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

src/api/services/approval.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,16 @@ async def dismiss_join_request(chat_id: int, user_id: int) -> bool:
3737
logger.warning(f"Bot is not a member of chat {chat_id}")
3838
elif "not_enough_rights" in error_msg:
3939
logger.warning(f"Bot lacks permissions in chat {chat_id}")
40+
elif "deactivated" in error_msg:
41+
logger.warning(f"User {user_id} is deactivated, skipping dismiss")
4042
else:
4143
logger.warning(f"Telegram API error on dismiss: {e}")
4244
return False
45+
except Exception as e:
46+
if "deactivated" in str(e).lower():
47+
logger.warning(f"User {user_id} is deactivated, skipping dismiss: {e}")
48+
return False
49+
raise
4350
finally:
4451
await bot.session.close()
4552

src/bot/tasks.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,14 @@ async def cleanup_and_dismiss_expired_requests() -> None:
1616
try:
1717
to_dismiss = await cleanup_expired_sessions()
1818
for chat_id, user_id in to_dismiss:
19-
await dismiss_join_request(chat_id=chat_id, user_id=user_id)
19+
try:
20+
await dismiss_join_request(chat_id=chat_id, user_id=user_id)
21+
except Exception as e:
22+
logger.warning(
23+
"Skip dismiss for user %s (chat %s): %s",
24+
user_id, chat_id, e,
25+
exc_info=False
26+
)
2027
except Exception as e:
2128
logger.exception("Error in cleanup_and_dismiss_expired_requests: %s", e)
2229

0 commit comments

Comments
 (0)