Skip to content

Your lightweight open-source personal agent.

fix: handle feishu login network errors

chengyongru5dfdd4f892a1
diff --git a/nanobot/channels/feishu.py b/nanobot/channels/feishu.py
index 75ac119e1..375d856a6 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 9758e3e3f..1f8685d46 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"