diff --git a/plugins/system/errorhandler.py b/plugins/system/errorhandler.py index 5408a84c..e0156f1f 100644 --- a/plugins/system/errorhandler.py +++ b/plugins/system/errorhandler.py @@ -6,7 +6,7 @@ import traceback import aiofiles from telegram import ReplyKeyboardRemove, Update from telegram.constants import ParseMode -from telegram.error import BadRequest, Forbidden +from telegram.error import BadRequest, Forbidden, NetworkError, TimedOut from telegram.ext import CallbackContext from core.bot import bot @@ -32,6 +32,13 @@ class ErrorHandler(Plugin): async def error_handler(self, update: object, context: CallbackContext) -> None: """记录错误并发送消息通知开发人员。 logger the error and send a telegram message to notify the developer.""" + if isinstance(NetworkError, context.error): + logger.error("Bot请求异常", exc_info=context.error) + return + if isinstance(TimedOut, context.error): + logger.error("Bot请求超时", exc_info=context.error) + return + logger.error("处理函数时发生异常") logger.exception(context.error, exc_info=(type(context.error), context.error, context.error.__traceback__))