🐛 Fix incorrect handling of timeout exceptions in httpx

This commit is contained in:
洛水居室 2023-03-14 10:40:27 +08:00
parent 503bd0b498
commit e24cd2a44d
No known key found for this signature in database
GPG Key ID: C9DE87DA724B88FC

View File

@ -6,7 +6,7 @@ from typing import Optional
import aiofiles import aiofiles
from aiohttp import ClientError, ClientConnectorError from aiohttp import ClientError, ClientConnectorError
from genshin import DataNotPublic, GenshinException, InvalidCookies, TooManyRequests from genshin import DataNotPublic, GenshinException, InvalidCookies, TooManyRequests
from httpx import Timeout as HttpxTimeout, HTTPError from httpx import HTTPError, TimeoutException
from telegram import ReplyKeyboardRemove, Update, InlineKeyboardMarkup, InlineKeyboardButton from telegram import ReplyKeyboardRemove, Update, InlineKeyboardMarkup, InlineKeyboardButton
from telegram.constants import ParseMode from telegram.constants import ParseMode
from telegram.error import BadRequest, Forbidden, TelegramError, TimedOut, NetworkError from telegram.error import BadRequest, Forbidden, TelegramError, TimedOut, NetworkError
@ -184,8 +184,9 @@ class ErrorHandler(Plugin):
return return
exc = context.error exc = context.error
notice: Optional[str] = None notice: Optional[str] = None
if isinstance(exc, HttpxTimeout): if isinstance(exc, TimeoutException):
notice = self.ERROR_MSG_PREFIX + " 连接连接服务器异常" notice = self.ERROR_MSG_PREFIX + " 连接连接服务器异常"
logger.warning("Httpx exception[%s]", str(exc))
if notice: if notice:
self.create_notice_task(update, context, notice) self.create_notice_task(update, context, notice)
raise ApplicationHandlerStop raise ApplicationHandlerStop