From 5dfdd4f892a1fcdc488e87b18db8c227178909d8 Mon Sep 17 00:00:00 2001 From: chengyongru Date: Thu, 18 Jun 2026 14:47:44 +0800 Subject: [PATCH] fix: handle feishu login network errors maintainer edit: keep QR login network failures on the expected failure path instead of crashing the channels login command. --- nanobot/channels/feishu.py | 4 +++- tests/channels/test_feishu_login.py | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/nanobot/channels/feishu.py b/nanobot/channels/feishu.py index 75ac119e..375d856a 100644 --- a/nanobot/channels/feishu.py +++ b/nanobot/channels/feishu.py @@ -460,9 +460,11 @@ def qr_register( Returns None on expected failures (network, auth denied, timeout). Unexpected errors (bugs, protocol regressions) propagate to the caller. """ + import httpx + try: return _qr_register_inner(initial_domain=initial_domain) - except (RuntimeError, OSError, json.JSONDecodeError) as exc: + except (RuntimeError, OSError, json.JSONDecodeError, httpx.HTTPError) as exc: print(f"[Warning] Registration failed: {exc}") return None diff --git a/tests/channels/test_feishu_login.py b/tests/channels/test_feishu_login.py index 9758e3e3..1f8685d4 100644 --- a/tests/channels/test_feishu_login.py +++ b/tests/channels/test_feishu_login.py @@ -1,5 +1,6 @@ import json +import httpx import pytest from nanobot.channels import feishu as feishu_module @@ -46,6 +47,15 @@ def test_begin_registration_requires_login_url(monkeypatch): feishu_module._begin_registration() +def test_qr_register_returns_none_on_network_error(monkeypatch): + def raise_connect_error(_base_url, _body): + raise httpx.ConnectError("network down") + + monkeypatch.setattr(feishu_module, "_post_registration", raise_connect_error) + + assert feishu_module.qr_register() is None + + @pytest.mark.asyncio async def test_feishu_login_creates_missing_active_config(monkeypatch, tmp_path): missing_config = tmp_path / "missing.json"