From ffb0f57d0651ae4636f3439df849654634c039dc Mon Sep 17 00:00:00 2001 From: sudoskys Date: Sun, 10 Dec 2023 17:18:03 +0800 Subject: [PATCH] feat(telegrambot): add error handling for ConnectTimeout 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. --- setting/telegrambot.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/setting/telegrambot.py b/setting/telegrambot.py index 58a94fd..7edda19 100644 --- a/setting/telegrambot.py +++ b/setting/telegrambot.py @@ -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 @@ -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}"