From da0faf6d98d59fcdecedbb0f61971ea507a2a46b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B4=9B=E6=B0=B4=E5=B1=85=E5=AE=A4?= Date: Thu, 24 Nov 2022 23:02:27 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Handle=20NetworkError=20and=20Ti?= =?UTF-8?q?medOut=20exceptions=20separately?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/system/errorhandler.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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__))