Skip to content

Commit ff270a6

Browse files
🔖 0.1.0-rc5
more error-prone session getting
1 parent c2f8b36 commit ff270a6

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

nonebot_plugin_htmlkit/__init__.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
)
2929

3030
driver = nonebot.get_driver()
31-
session = driver.get_session() if isinstance(driver, HTTPClientMixin) else None
31+
session = None
3232

3333

3434
def init_fontconfig(**kwargs: Any):
@@ -40,10 +40,20 @@ def init_fontconfig(**kwargs: Any):
4040

4141
@driver.on_startup
4242
async def _():
43+
global session
44+
4345
init_fontconfig()
4446

45-
if session is not None:
46-
await session.setup()
47+
try:
48+
if isinstance(driver, HTTPClientMixin):
49+
driver_session = driver.get_session()
50+
await driver_session.setup()
51+
session = driver_session
52+
logger.info("Got HTTP session.")
53+
except Exception as e:
54+
logger.opt(exception=e).error(
55+
"Error while getting HTTP session and setting up."
56+
)
4757

4858

4959
ImgFetchFn = Callable[[str], Coroutine[Any, Any, bytes | None]]

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "nonebot-plugin-htmlkit"
3-
version = "0.1.0-rc4"
3+
version = "0.1.0-rc5"
44
description = "Lightweight HTML rendering plugin for NoneBot"
55
readme = "README.md"
66
requires-python = ">=3.10"

0 commit comments

Comments
 (0)