Skip to content

Commit cc3b5c5

Browse files
committed
chore: Add defensive check for response status
1 parent b38695e commit cc3b5c5

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

packages/toolbox-core/src/toolbox_core/client.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,11 @@ async def load_tool(
193193
# request the definition of the tool from the server
194194
url = f"{self.__base_url}/api/tool/{name}"
195195
async with self.__session.get(url, headers=resolved_headers) as response:
196+
if not response.ok:
197+
error_text = await response.text()
198+
raise RuntimeError(
199+
f"API request failed with status {response.status} ({response.reason}). Server response: {error_text}"
200+
)
196201
json = await response.json()
197202
manifest: ManifestSchema = ManifestSchema(**json)
198203

packages/toolbox-core/src/toolbox_core/tool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ async def __call__(self, *args: Any, **kwargs: Any) -> str:
289289
headers=headers,
290290
) as resp:
291291
body = await resp.json()
292-
if resp.status < 200 or resp.status >= 300:
292+
if not resp.ok:
293293
err = body.get("error", f"unexpected status from server: {resp.status}")
294294
raise Exception(err)
295295
return body.get("result", body)

0 commit comments

Comments
 (0)