Skip to content

docs: Improve API error handling for toolbox-core client #275

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 11, 2025
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
11 changes: 10 additions & 1 deletion packages/toolbox-core/src/toolbox_core/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion packages/toolbox-core/src/toolbox_core/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down