Client._request no longer prepends 'API error:' to the exception message since _format_error in server.py already adds that prefix. Closes #7
This commit is contained in:
2 files changed
+28
-2
No files matched your search
@@ -171,7 +171,7 @@ class NpmClient:
|
||||
raise NpmNotFoundError(f"Resource not found: {endpoint}")
|
||||
|
||||
if response.status_code >= 400:
|
||||
raise NpmApiError(f"API error: {response.text}", status_code=response.status_code)
|
||||
raise NpmApiError(response.text, status_code=response.status_code)
|
||||
|
||||
return response
|
||||
|
||||
|
||||
+27
-1
@@ -4,7 +4,7 @@ import pytest
|
||||
from httpx import Response
|
||||
|
||||
from npm_mcp.client import NpmClient
|
||||
from npm_mcp.exceptions import NpmAuthenticationError, NpmConnectionError
|
||||
from npm_mcp.exceptions import NpmApiError, NpmAuthenticationError, NpmConnectionError
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -227,3 +227,29 @@ class TestNpmClientEndpoints:
|
||||
assert host.forward_port == 3000
|
||||
assert host.ssl_forced is True
|
||||
assert host.certificate_id == 24
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_api_error_no_double_prefix(self, httpx_mock, mock_token_response):
|
||||
"""Test that API errors don't have a duplicated 'API error:' prefix."""
|
||||
httpx_mock.add_response(
|
||||
method="POST",
|
||||
url="http://localhost:81/api/tokens",
|
||||
json=mock_token_response,
|
||||
)
|
||||
httpx_mock.add_response(
|
||||
method="GET",
|
||||
url="http://localhost:81/api/nginx/proxy-hosts?expand=owner%2Ccertificate",
|
||||
json={"error": {"message": "Something went wrong"}},
|
||||
status_code=400,
|
||||
)
|
||||
|
||||
async with NpmClient(
|
||||
base_url="http://localhost:81/api",
|
||||
identity="test@test.com",
|
||||
secret="password",
|
||||
) as client:
|
||||
with pytest.raises(NpmApiError) as exc_info:
|
||||
await client.get_proxy_hosts()
|
||||
|
||||
msg = str(exc_info.value)
|
||||
assert msg.count("API error") == 0, f"Client should not prefix error: {msg}"
|
||||
Reference in new issue
Block a user