fix(cli): keep the proxy's response on a teams 401 so lite shows the proxy's reason

This commit is contained in:
mateo-berri 2026-10-29 02:50:39 -07:00
parent c5ed701362
commit 0b6e096046
2 changed files with 15 additions and 5 deletions

View file

@ -65,7 +65,9 @@ class TeamsManagementClient:
response: Final = requests.get(url, headers=self._get_headers(), params=params, timeout=self._timeout)
if response.status_code == 401:
raise UnauthorizedError("Authentication failed. Check your API key.")
raise UnauthorizedError(
requests.exceptions.HTTPError("Authentication failed. Check your API key.", response=response)
)
response.raise_for_status()
return response.json()
@ -122,7 +124,9 @@ class TeamsManagementClient:
response: Final = requests.get(url, headers=self._get_headers(), params=params, timeout=self._timeout)
if response.status_code == 401:
raise UnauthorizedError("Authentication failed. Check your API key.")
raise UnauthorizedError(
requests.exceptions.HTTPError("Authentication failed. Check your API key.", response=response)
)
response.raise_for_status()
return response.json()
@ -143,7 +147,9 @@ class TeamsManagementClient:
response: Final = requests.get(url, headers=self._get_headers(), timeout=self._timeout)
if response.status_code == 401:
raise UnauthorizedError("Authentication failed. Check your API key.")
raise UnauthorizedError(
requests.exceptions.HTTPError("Authentication failed. Check your API key.", response=response)
)
response.raise_for_status()
return response.json()

View file

@ -541,8 +541,12 @@ def test_a_rejected_explicit_key_fails_cleanly_without_opening_a_browser(
@pytest.mark.parametrize(
("command", "method", "path"),
[(["users", "list"], "GET", "/user/list"), (["keys", "generate"], "POST", "/key/generate")],
ids=["users", "keys"],
[
(["users", "list"], "GET", "/user/list"),
(["keys", "generate"], "POST", "/key/generate"),
(["teams", "list"], "GET", "/team/list"),
],
ids=["users", "keys", "teams"],
)
def test_a_rejected_explicit_key_names_the_reason_the_proxy_gave_without_echoing_the_key(
requests_mock: Mocker,