Skip to content

The agent that grows with you

refactor(auth): classify a non-dict Nous refresh error body as empty

kshitijk4poord933ac2104c9
diff --git a/hermes_cli/auth_nous.py b/hermes_cli/auth_nous.py
index 90ece5b1d6e..93b74fc9290 100644
--- a/hermes_cli/auth_nous.py
+++ b/hermes_cli/auth_nous.py
@@ -618,10 +618,12 @@ def _refresh_access_token(
error_payload = response.json()
except Exception:
error_payload = {}
+ if not isinstance(error_payload, dict):
+ error_payload = {}
# Only an explicit OAuth grant-dead code is terminal: a 429/404 gateway body without an
# ``error`` key says nothing about the refresh token, so it must not wipe credentials.
- # A 401/403 from the token endpoint is the exception: it always means the refresh token
- # itself was rejected (same rule as the Codex sibling), so keep the base grant-dead default.
+ # A 401/403 without an ``error`` code still means the token endpoint rejected the refresh
+ # token, so it is reported as ``invalid_grant`` (terminal) rather than left unclassified.
raw_code = error_payload.get("error")
if raw_code is None and response.status_code in {401, 403}:
raw_code = "invalid_grant"
diff --git a/tests/hermes_cli/test_auth_nous_provider.py b/tests/hermes_cli/test_auth_nous_provider.py
index a3c59e81ddb..c7c49fa2777 100644
--- a/tests/hermes_cli/test_auth_nous_provider.py
+++ b/tests/hermes_cli/test_auth_nous_provider.py
@@ -697,7 +697,7 @@ def test_refresh_token_reuse_detection_surfaces_actionable_message():
(403, ValueError("not json"), "invalid_grant", True),
],
)
-def test_refresh_token_exchange_without_grant_error_code_is_not_terminal(
+def test_refresh_token_exchange_error_classification(
status_code, body, expected_code, expected_terminal
):
"""A Portal 5xx is transient even when its body is not OAuth JSON (#120976), and a