fix(V2): map Deribit upstream 5xx / non-JSON to clean HTTPException 502
Cloudflare 5xx pages from Deribit testnet were leaking through the JSON parser as JSONDecodeError → UNHANDLED_EXCEPTION. Wrap response parsing so upstream errors surface as a retryable HTTP_502 envelope instead. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -154,6 +154,29 @@ async def test_get_account_summary(httpx_mock: HTTPXMock, client: DeribitClient)
|
||||
assert result["balance"] == 900.0
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_upstream_5xx_raises_clean_http_error(
|
||||
httpx_mock: HTTPXMock, client: DeribitClient
|
||||
):
|
||||
"""Upstream Deribit 5xx (non-JSON body) → HTTPException 502, non JSONDecodeError."""
|
||||
from fastapi import HTTPException
|
||||
|
||||
httpx_mock.add_response(
|
||||
url=re.compile(r"https://test\.deribit\.com/api/v2/public/get_tradingview_chart_data"),
|
||||
status_code=502,
|
||||
text="<html>Bad Gateway</html>",
|
||||
)
|
||||
with pytest.raises(HTTPException) as exc_info:
|
||||
await client.get_historical(
|
||||
instrument="BTC-PERPETUAL",
|
||||
start_date="2026-05-09T00:00:00",
|
||||
end_date="2026-05-10T00:00:00",
|
||||
resolution="1h",
|
||||
)
|
||||
assert exc_info.value.status_code == 502
|
||||
assert "Deribit upstream" in str(exc_info.value.detail)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_private_call_with_bad_auth_returns_error_envelope(
|
||||
httpx_mock: HTTPXMock, client: DeribitClient
|
||||
|
||||
Reference in New Issue
Block a user