Use Claude Code, Codex, VSCode, Pi, and OpenCode (and 6 other harnesses) for free (1.3B+ free tokens) from your terminal, app, IDE, or phone, and now from the browser with native browser sessions (multi-harness + multi-model) like OpenClaw (voice supported + ToS friendly)
Python
fix(providers): map httpx exceptions natively and remove type ignores
Alishahryar11aedf4763c9f
diff --git a/providers/common/error_mapping.py b/providers/common/error_mapping.pyindex dfb156da..55f622e5 100644--- a/providers/common/error_mapping.py+++ b/providers/common/error_mapping.py@@ -62,8 +62,10 @@ def append_request_id(message: str, request_id: str | None) -> str:def map_error(e: Exception) -> Exception:- """Map OpenAI exception to specific ProviderError."""+ """Map OpenAI or HTTPX exception to specific ProviderError."""message = get_user_facing_error_message(e)++ # Map OpenAI Specific Errorsif isinstance(e, openai.AuthenticationError):return AuthenticationError(message, raw_error=str(e))if isinstance(e, openai.RateLimitError):@@ -82,4 +84,20 @@ def map_error(e: Exception) -> Exception:message, status_code=getattr(e, "status_code", 500), raw_error=str(e))+ # Map raw HTTPX Errors+ if isinstance(e, httpx.HTTPStatusError):+ status = e.response.status_code+ if status in (401, 403):+ return AuthenticationError(message, raw_error=str(e))+ if status == 429:+ GlobalRateLimiter.get_instance().set_blocked(60)+ return RateLimitError(message, raw_error=str(e))+ if status == 400:+ return InvalidRequestError(message, raw_error=str(e))+ if status >= 500:+ if status in (502, 503, 504):+ return OverloadedError(message, raw_error=str(e))+ return APIError(message, status_code=status, raw_error=str(e))+ return APIError(message, status_code=status, raw_error=str(e))+return ediff --git a/providers/lmstudio/client.py b/providers/lmstudio/client.pyindex ce5ababc..7b5dbdf0 100644--- a/providers/lmstudio/client.py+++ b/providers/lmstudio/client.py@@ -104,10 +104,18 @@ class LMStudioProvider(BaseProvider):)if response.status_code != 200:- text = await response.aread()- error_msg = f"HTTP {response.status_code}: {text.decode('utf-8', errors='replace')}"- logger.error("{}_ERROR:{} {}", tag, req_tag, error_msg)- raise RuntimeError(f"LMStudio natively returned error: {error_msg}")+ try:+ response.raise_for_status()+ except httpx.HTTPStatusError as e:+ text = await response.aread()+ logger.error(+ "{}_ERROR:{} HTTP {}: {}",+ tag,+ req_tag,+ response.status_code,+ text.decode("utf-8", errors="replace"),+ )+ raise easync for line in response.aiter_lines():if line:diff --git a/tests/providers/test_lmstudio.py b/tests/providers/test_lmstudio.pyindex a0910b6d..201e5910 100644--- a/tests/providers/test_lmstudio.py+++ b/tests/providers/test_lmstudio.py@@ -167,8 +167,6 @@ async def test_stream_response(lmstudio_provider):async def test_stream_response_adds_max_tokens_if_missing(lmstudio_provider):"""Fallback max_tokens to 81920 if not present."""req = MockRequest()- # Replace the existing method completely to avoid proxy mapping errors from type checkers- req.model_dump = lambda **kwargs: {"model": "test"} # type: ignoremock_response = MagicMock()mock_response.status_code = 200@@ -179,6 +177,7 @@ async def test_stream_response_adds_max_tokens_if_missing(lmstudio_provider):mock_response.aiter_lines = empty_aiterwith (+ patch.object(req, "model_dump", return_value={"model": "test"}),patch.object(lmstudio_provider._client, "build_request") as mock_build,patch.object(lmstudio_provider._client,@@ -202,6 +201,11 @@ async def test_stream_error_status_code(lmstudio_provider):mock_response = MagicMock()mock_response.status_code = 500mock_response.aread = AsyncMock(return_value=b"Internal Server Error")+ mock_response.raise_for_status = MagicMock(+ side_effect=httpx.HTTPStatusError(+ "Internal Server Error", request=MagicMock(), response=mock_response+ )+ )with (patch.object(