Skip to content

Commit 6636d77

Browse files
fix(#3109): catch httpx.HTTPStatusError in Watsonx model discovery
WatsonxIAMAuth.raise_for_status() raises httpx.HTTPStatusError on IAM token exchange failures (401/403/5xx), which is not a subclass of openai.APIError. This escaped the except clause in _discover_models, propagating unwrapped instead of as ModelDiscoveryError. Widen the except tuple to (APIError, httpx.HTTPStatusError) so IAM failures are wrapped consistently with other discovery errors. Add a parametrized test case for httpx.HTTPStatusError to the existing test_discover_models_wraps_api_error test. Closes #3109
1 parent 0b7d213 commit 6636d77

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

‎src/providers/inference/watsonx/provider.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import asyncio
66
from typing import TYPE_CHECKING, Any, Optional
77

8+
import httpx
89
from openai import APIError
910
from pydantic_ai.embeddings import EmbeddingModel
1011
from pydantic_ai.embeddings.openai import OpenAIEmbeddingModel
@@ -63,7 +64,7 @@ async def _discover_models(self) -> list[DiscoveredModel]:
6364
),
6465
self._list_foundation_model_functions(),
6566
)
66-
except APIError as exc:
67+
except (APIError, httpx.HTTPStatusError) as exc:
6768
raise ModelDiscoveryError(self.provider_id) from exc
6869

6970
discovered: list[DiscoveredModel] = []

‎tests/unit/providers/inference/watsonx/test_provider.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,13 @@ async def test_discover_models_keeps_chat_and_embedding_only(
128128
),
129129
body=None,
130130
),
131+
httpx.HTTPStatusError(
132+
"IAM token exchange failed",
133+
request=httpx.Request("POST", "https://iam.cloud.ibm.com/identity/token"),
134+
response=httpx.Response(401),
135+
),
131136
],
132-
ids=["connection-error", "authentication-error"],
137+
ids=["connection-error", "authentication-error", "iam-http-status-error"],
133138
)
134139
async def test_discover_models_wraps_api_error(
135140
provider: WatsonxInferenceProvider,

0 commit comments

Comments
 (0)