Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/providers/inference/watsonx/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import asyncio
from typing import TYPE_CHECKING, Any, Optional

import httpx
from openai import APIError
from pydantic_ai.embeddings import EmbeddingModel
from pydantic_ai.embeddings.openai import OpenAIEmbeddingModel
Expand Down Expand Up @@ -63,7 +64,7 @@ async def _discover_models(self) -> list[DiscoveredModel]:
),
self._list_foundation_model_functions(),
)
except APIError as exc:
except (APIError, httpx.HTTPStatusError) as exc:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[low] edge-case

The except (APIError, httpx.HTTPStatusError) handler does not catch raw httpx transport errors (httpx.ConnectError, httpx.TimeoutException). However, these would only be unhandled if they escape the openai SDK's own error-wrapping layer, which normally converts them to APIConnectionError/APITimeoutError (both subclasses of APIError). The practical risk is low and unconfirmed.

raise ModelDiscoveryError(self.provider_id) from exc

discovered: list[DiscoveredModel] = []
Expand Down
7 changes: 6 additions & 1 deletion tests/unit/providers/inference/watsonx/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,13 @@ async def test_discover_models_keeps_chat_and_embedding_only(
),
body=None,
),
httpx.HTTPStatusError(
"IAM token exchange failed",
request=httpx.Request("POST", "https://iam.cloud.ibm.com/identity/token"),
response=httpx.Response(401),
),
],
ids=["connection-error", "authentication-error"],
ids=["connection-error", "authentication-error", "iam-http-status-error"],
)
async def test_discover_models_wraps_api_error(
provider: WatsonxInferenceProvider,
Expand Down
Loading