From e7cea2c77dc9d117dd3bcc1846bd49f3ec38b076 Mon Sep 17 00:00:00 2001 From: Jesus Lopez Date: Mon, 2 Mar 2026 09:10:20 -0800 Subject: [PATCH] fix(client): raise AuthenticationError instead of RuntimeError on login failure `_http_login()` now raises `AuthenticationError` (like `_relogin()` does) so consumers can catch a single typed exception for all credential failures. Fixes: #32 Co-Authored-By: Claude Sonnet 4.6 --- src/socketry/client.py | 2 +- tests/test_client.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/socketry/client.py b/src/socketry/client.py index 5b4114f..9b6f243 100644 --- a/src/socketry/client.py +++ b/src/socketry/client.py @@ -854,7 +854,7 @@ async def _http_login( if body.get("code") != 0: msg = body.get("msg", "unknown error") - raise RuntimeError(f"Login failed: {msg}") + raise AuthenticationError(f"Login failed: {msg}") data = body["data"] token = body["token"] diff --git a/tests/test_client.py b/tests/test_client.py index cb7ac3d..8813a15 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -290,7 +290,7 @@ async def test_login_no_devices(self): async def test_login_failure_code(self): with aioresponses() as m: m.post(_LOGIN_URL, payload={"code": 1, "msg": "Bad credentials"}) - with pytest.raises(RuntimeError, match="Login failed: Bad credentials"): + with pytest.raises(AuthenticationError, match="Login failed: Bad credentials"): await _http_login("bad@example.com", "wrong") async def test_login_http_error(self):