From 86481c8b6910c78eeb7be9632b7fc81d321f3d1d Mon Sep 17 00:00:00 2001 From: vivan070707-ctrl Date: Tue, 24 Mar 2026 19:35:19 +0530 Subject: [PATCH 1/3] Enhance AxmeAuthError messages for status codes 401 and 403 Improve error messages for 401 and 403 auth failures --- axme_sdk/client.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/axme_sdk/client.py b/axme_sdk/client.py index 52ed4b4..3dcfdfb 100644 --- a/axme_sdk/client.py +++ b/axme_sdk/client.py @@ -1936,8 +1936,16 @@ def _raise_http_error(self, response: httpx.Response) -> None: "retry_after": retry_after, } status_code = response.status_code - if status_code in (401, 403): - raise AxmeAuthError(status_code, message, **kwargs) + if status_code == 401: + raise AxmeAuthError( + status_code, + "Invalid API key. Please check your AXME_API_KEY.", + **kwargs) + if status_code == 403: + raise AxmeAuthError( + status_code, + "Access denied. You do not have permission to perform this action.", + **kwargs) if status_code in (400, 409, 413, 422): raise AxmeValidationError(status_code, message, **kwargs) if status_code == 429: From 28159fca7ab2b537caea4934324b8c84dc3ade90 Mon Sep 17 00:00:00 2001 From: vivan070707-ctrl Date: Tue, 24 Mar 2026 23:41:09 +0530 Subject: [PATCH 2/3] Improve error messages for API key and permissions Fix: prepend user-friendly hint while preserving server message for 401/403 --- axme_sdk/client.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/axme_sdk/client.py b/axme_sdk/client.py index 3dcfdfb..1214c20 100644 --- a/axme_sdk/client.py +++ b/axme_sdk/client.py @@ -1939,12 +1939,12 @@ def _raise_http_error(self, response: httpx.Response) -> None: if status_code == 401: raise AxmeAuthError( status_code, - "Invalid API key. Please check your AXME_API_KEY.", + f"API key invalid - check AXME_API_KEY or run `axme login`. Server: {message}" **kwargs) if status_code == 403: raise AxmeAuthError( status_code, - "Access denied. You do not have permission to perform this action.", + f"Access denied. Check permissions. Server: {message}" **kwargs) if status_code in (400, 409, 413, 422): raise AxmeValidationError(status_code, message, **kwargs) From b44d0e97587405ad29e77ede3012108669973a53 Mon Sep 17 00:00:00 2001 From: vivan070707-ctrl Date: Tue, 24 Mar 2026 23:49:01 +0530 Subject: [PATCH 3/3] Implement test for 401 error message details Test: add 401 error message test to verify hint and server message --- tests/test_client.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/test_client.py b/tests/test_client.py index b0f3ed4..c5c1c74 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -1886,7 +1886,6 @@ def handler(request: httpx.Request) -> httpx.Response: result = next(client.listen("org/ws/bot")) assert result["intent_id"] == "x1" - def test_listen_raises_auth_error_on_401() -> None: from axme.exceptions import AxmeAuthError @@ -1896,3 +1895,14 @@ def handler(request: httpx.Request) -> httpx.Response: client = _client(handler) with pytest.raises(AxmeAuthError): list(client.listen("org/ws/bot")) + +def test_401_error_message_contains_hint_and_server_message(): + def handler(request: httpx.Request) -> httpx.Response: + return httpx.Response(401, json={"message": "API key expired"}) + client = _client(handler) + with pytest.raises(AxmeAuthError) as exc_info: + client.health() + msg = str(exc_info.value) + assert "API key invalid" in msg + assert "API key expired" in msg +