fix(V2): Deribit _authenticate gestisce error envelope (no più KeyError 'result')
Quando Deribit risponde con {"error": {...}} su public/auth (creds errate,
scope mancante, env mismatch), il client esplodeva con KeyError: 'result' →
500 UNHANDLED_EXCEPTION sui tool privati (get_account_summary, get_positions).
Ora _authenticate solleva DeribitAuthError tipizzata, _request la converte
in error envelope coerente con il resto del flusso.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -154,6 +154,23 @@ async def test_get_account_summary(httpx_mock: HTTPXMock, client: DeribitClient)
|
||||
assert result["balance"] == 900.0
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_private_call_with_bad_auth_returns_error_envelope(
|
||||
httpx_mock: HTTPXMock, client: DeribitClient
|
||||
):
|
||||
"""Auth fallita (creds errate / scope mancante) → error envelope, non KeyError."""
|
||||
httpx_mock.add_response(
|
||||
url=re.compile(r"https://test\.deribit\.com/api/v2/public/auth"),
|
||||
json={"error": {"code": 13004, "message": "invalid_credentials"}},
|
||||
is_reusable=True,
|
||||
)
|
||||
summary = await client.get_account_summary("USDC")
|
||||
assert summary["equity"] == 0
|
||||
assert "invalid_credentials" in summary["error"]
|
||||
positions = await client.get_positions("USDC")
|
||||
assert positions == []
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_place_order(httpx_mock: HTTPXMock, client: DeribitClient):
|
||||
httpx_mock.add_response(
|
||||
|
||||
Reference in New Issue
Block a user