Skip to content

Commit

Permalink
feat(telegrambot): add error handling for ConnectTimeout
Browse files Browse the repository at this point in the history
Added error handling to catch ConnectTimeout exception when connecting to Telegram API. Displays an error message and raises the exception if a ConnectTimeout error occurs.
  • Loading branch information
sudoskys committed Dec 10, 2023
1 parent 72c2a06 commit ffb0f57
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion setting/telegrambot.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# @Software: PyCharm
from typing import Optional

import requests
from dotenv import load_dotenv
from loguru import logger
from pydantic import Field, model_validator
Expand Down Expand Up @@ -49,8 +50,13 @@ def bot_validator(self):
self.bot_id = str(_bot.id)
self.bot_username = _bot.username
self.bot_link = f"https://t.me/{self.bot_username}"
except requests.exceptions.ConnectTimeout:
logger.error(
"\n🍀TelegramBot Connect Error --error ConnectTimeout, Please Check Your Network To Telegram"
)
raise requests.exceptions.ConnectTimeout
except Exception as e:
logger.error(f"\n🍀TelegramBot Token Not Set --error {e}")
logger.error(f"\n🍀TelegramBot Connect Error --error {e}")
else:
logger.success(
f"🍀TelegramBot Init Connection Success --bot_name {self.bot_username} --bot_id {self.bot_id}"
Expand Down

0 comments on commit ffb0f57

Please sign in to comment.