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.
This commit is contained in:
@@ -460,9 +460,11 @@ def qr_register(
|
|||||||
Returns None on expected failures (network, auth denied, timeout).
|
Returns None on expected failures (network, auth denied, timeout).
|
||||||
Unexpected errors (bugs, protocol regressions) propagate to the caller.
|
Unexpected errors (bugs, protocol regressions) propagate to the caller.
|
||||||
"""
|
"""
|
||||||
|
import httpx
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return _qr_register_inner(initial_domain=initial_domain)
|
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}")
|
print(f"[Warning] Registration failed: {exc}")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import json
|
import json
|
||||||
|
|
||||||
|
import httpx
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from nanobot.channels import feishu as feishu_module
|
from nanobot.channels import feishu as feishu_module
|
||||||
@@ -46,6 +47,15 @@ def test_begin_registration_requires_login_url(monkeypatch):
|
|||||||
feishu_module._begin_registration()
|
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
|
@pytest.mark.asyncio
|
||||||
async def test_feishu_login_creates_missing_active_config(monkeypatch, tmp_path):
|
async def test_feishu_login_creates_missing_active_config(monkeypatch, tmp_path):
|
||||||
missing_config = tmp_path / "missing.json"
|
missing_config = tmp_path / "missing.json"
|
||||||
|
|||||||
Reference in New Issue
Block a user