diff --git a/packages/toolbox-core/src/toolbox_core/client.py b/packages/toolbox-core/src/toolbox_core/client.py index 1fcea46c..25a3d267 100644 --- a/packages/toolbox-core/src/toolbox_core/client.py +++ b/packages/toolbox-core/src/toolbox_core/client.py @@ -13,7 +13,6 @@ # limitations under the License. -from asyncio import get_running_loop from types import MappingProxyType from typing import Any, Awaitable, Callable, Mapping, Optional, Union @@ -194,6 +193,11 @@ async def load_tool( # request the definition of the tool from the server url = f"{self.__base_url}/api/tool/{name}" async with self.__session.get(url, headers=resolved_headers) as response: + if not response.ok: + error_text = await response.text() + raise RuntimeError( + f"API request failed with status {response.status} ({response.reason}). Server response: {error_text}" + ) json = await response.json() manifest: ManifestSchema = ManifestSchema(**json) @@ -272,6 +276,11 @@ async def load_toolset( # Request the definition of the toolset from the server url = f"{self.__base_url}/api/toolset/{name or ''}" async with self.__session.get(url, headers=resolved_headers) as response: + if not response.ok: + error_text = await response.text() + raise RuntimeError( + f"API request failed with status {response.status} ({response.reason}). Server response: {error_text}" + ) json = await response.json() manifest: ManifestSchema = ManifestSchema(**json) diff --git a/packages/toolbox-core/src/toolbox_core/tool.py b/packages/toolbox-core/src/toolbox_core/tool.py index ebfa8358..1545ded4 100644 --- a/packages/toolbox-core/src/toolbox_core/tool.py +++ b/packages/toolbox-core/src/toolbox_core/tool.py @@ -289,7 +289,7 @@ async def __call__(self, *args: Any, **kwargs: Any) -> str: headers=headers, ) as resp: body = await resp.json() - if resp.status < 200 or resp.status >= 300: + if not resp.ok: err = body.get("error", f"unexpected status from server: {resp.status}") raise Exception(err) return body.get("result", body)