Skip to content

Commit 5187733

Browse files
balogh.adam@icloud.comclaude
andcommitted
raise HTTPStatusError so retry path skips, and keep tests green
Uses status_code gate (not is_error) and wraps the decoded x402 detail in httpx.HTTPStatusError so _call_with_tee_retry correctly skips retries on server-side failures. Adds request/url/headers to the test fake to match the httpx Response contract. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 043f7be commit 5187733

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

src/opengradient/client/llm.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,8 +388,12 @@ async def _request() -> TextGenerationOutput:
388388
timeout=_REQUEST_TIMEOUT,
389389
)
390390
raw_body = await response.aread()
391-
if response.is_error:
392-
raise RuntimeError(_format_http_error(response, raw_body))
391+
if response.status_code >= 400:
392+
raise httpx.HTTPStatusError(
393+
_format_http_error(response, raw_body),
394+
request=response.request,
395+
response=response,
396+
)
393397
result = json.loads(raw_body.decode())
394398

395399
choices = result.get("choices")

tests/llm_test.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import json
88
import ssl
99
from contextlib import asynccontextmanager
10-
from typing import List
10+
from typing import Dict, List
1111
from unittest.mock import AsyncMock, MagicMock, patch
1212

1313
import httpx
@@ -80,6 +80,9 @@ class _FakeResponse:
8080
def __init__(self, status_code: int, body: bytes):
8181
self.status_code = status_code
8282
self._body = body
83+
self.headers: Dict[str, str] = {}
84+
self.request = MagicMock()
85+
self.url = "https://test.tee.server/v1/chat/completions"
8386

8487
def raise_for_status(self):
8588
pass

0 commit comments

Comments
 (0)