From 05230558b004ecc3deb65b1c5cfe511e64bda35a Mon Sep 17 00:00:00 2001 From: yanyongyu Date: Thu, 19 Aug 2021 23:12:15 +0800 Subject: [PATCH] :bug: fix playwright timeout handle --- .../github/plugins/github_issue/__init__.py | 23 ++++++++++++++----- .../github/plugins/github_reply/content.py | 23 ++++++++++++++----- .../github/plugins/github_reply/diff.py | 5 +++- 3 files changed, 38 insertions(+), 13 deletions(-) diff --git a/src/plugins/github/plugins/github_issue/__init__.py b/src/plugins/github/plugins/github_issue/__init__.py index af73d40..13ac689 100644 --- a/src/plugins/github/plugins/github_issue/__init__.py +++ b/src/plugins/github/plugins/github_issue/__init__.py @@ -4,7 +4,7 @@ @Author : yanyongyu @Date : 2021-03-09 15:15:02 @LastEditors : yanyongyu -@LastEditTime : 2021-07-02 17:48:19 +@LastEditTime : 2021-08-19 23:07:33 @Description : None @GitHub : https://github.com/yanyongyu """ @@ -16,6 +16,7 @@ from typing import Dict from nonebot import on_regex from nonebot.typing import T_State +from playwright.async_api import TimeoutError from httpx import HTTPStatusError, TimeoutException from nonebot.adapters.cqhttp import Bot, MessageEvent, MessageSegment, GroupMessageEvent @@ -71,11 +72,19 @@ async def handle(bot: Bot, event: MessageEvent, state: T_State): except HTTPStatusError: await issue.finish(f"仓库{owner}/{repo}不存在issue#{number}!") return - img = await issue_to_image(owner, repo, issue_) - if img: - await send_github_message( - issue, owner, repo, number, - MessageSegment.image(f"base64://{base64.b64encode(img).decode()}")) + + try: + img = await issue_to_image(owner, repo, issue_) + except TimeoutException: + await issue.finish(f"获取issue数据超时!请尝试重试") + except TimeoutError: + await issue.finish(f"生成图片超时!请尝试重试") + else: + if img: + await send_github_message( + issue_short, owner, repo, number, + MessageSegment.image( + f"base64://{base64.b64encode(img).decode()}")) issue_short = on_regex(ISSUE_REGEX, @@ -118,6 +127,8 @@ async def handle_short(bot: Bot, event: GroupMessageEvent, state: T_State): img = await issue_to_image(owner, repo, issue_) except TimeoutException: await issue.finish(f"获取issue数据超时!请尝试重试") + except TimeoutError: + await issue.finish(f"生成图片超时!请尝试重试") else: if img: await send_github_message( diff --git a/src/plugins/github/plugins/github_reply/content.py b/src/plugins/github/plugins/github_reply/content.py index ae0fc1d..6ee2f20 100644 --- a/src/plugins/github/plugins/github_reply/content.py +++ b/src/plugins/github/plugins/github_reply/content.py @@ -4,7 +4,7 @@ @Author : yanyongyu @Date : 2021-03-26 14:45:05 @LastEditors : yanyongyu -@LastEditTime : 2021-05-30 21:02:19 +@LastEditTime : 2021-08-19 23:09:17 @Description : None @GitHub : https://github.com/yanyongyu """ @@ -14,6 +14,7 @@ import base64 from nonebot import on_command from nonebot.typing import T_State +from playwright.async_api import TimeoutError from httpx import HTTPStatusError, TimeoutException from nonebot.adapters.cqhttp import Bot, MessageEvent, MessageSegment @@ -53,8 +54,18 @@ async def handle_content(bot: Bot, event: MessageEvent, state: T_State): await content.finish(f"仓库{message_info.owner}/{message_info.repo}" f"不存在issue#{message_info.number}!") return - img = await issue_to_image(message_info.owner, message_info.repo, issue_) - if img: - await send_github_message( - content, message_info.owner, message_info.repo, message_info.number, - MessageSegment.image(f"base64://{base64.b64encode(img).decode()}")) + + try: + img = await issue_to_image(message_info.owner, message_info.repo, + issue_) + except TimeoutException: + await content.finish(f"获取issue数据超时!请尝试重试") + except TimeoutError: + await content.finish(f"生成图片超时!请尝试重试") + else: + if img: + await send_github_message( + content, message_info.owner, message_info.repo, + message_info.number, + MessageSegment.image( + f"base64://{base64.b64encode(img).decode()}")) diff --git a/src/plugins/github/plugins/github_reply/diff.py b/src/plugins/github/plugins/github_reply/diff.py index 82f34c9..31a0e92 100644 --- a/src/plugins/github/plugins/github_reply/diff.py +++ b/src/plugins/github/plugins/github_reply/diff.py @@ -4,7 +4,7 @@ @Author : yanyongyu @Date : 2021-03-26 14:59:59 @LastEditors : yanyongyu -@LastEditTime : 2021-07-02 17:45:46 +@LastEditTime : 2021-08-19 23:09:30 @Description : None @GitHub : https://github.com/yanyongyu """ @@ -14,6 +14,7 @@ import base64 from nonebot import on_command from nonebot.typing import T_State +from playwright.async_api import TimeoutError from httpx import HTTPStatusError, TimeoutException from nonebot.adapters.cqhttp import Bot, MessageEvent, MessageSegment @@ -59,6 +60,8 @@ async def handle_diff(bot: Bot, event: MessageEvent, state: T_State): issue_) except TimeoutException: await diff.finish(f"获取diff数据超时!请尝试重试") + except TimeoutError: + await diff.finish(f"生成图片超时!请尝试重试") else: if img: await send_github_message(