Skip to content

Commit 24e74fc

Browse files
CopilotOhYee
andauthored
fix: use ClientError for non-JSON 2xx; document HTTPError.__str__ format change
Agent-Logs-Url: https://github.com/Serverless-Devs/agentrun-sdk-python/sessions/521d41f7-af5d-44a2-9ba2-b04863849851 Co-authored-by: OhYee <13498329+OhYee@users.noreply.github.com>
1 parent 887c087 commit 24e74fc

4 files changed

Lines changed: 9 additions & 4 deletions

File tree

RELEASE_NOTES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
`message`.
1515
- Existing code that checked returned dictionaries for `code` and `requestId`
1616
must migrate to `try` / `except ClientError` / `except ServerError`.
17+
- `HTTPError.__str__()` output format has changed. The old format unconditionally
18+
included `"Request ID: None. Details: {}"` even when those fields were empty.
19+
The new format only includes non-empty fields and uses `". "` as separator.
20+
Code that parses this string representation (e.g. log parsers or test assertions
21+
on `str(error)`) must be updated.
1722

1823
### Migration
1924

agentrun/sandbox/api/__sandbox_data_async_template.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def _parse_success_response(response: httpx.Response) -> Dict[str, Any]:
128128
except ValueError as e:
129129
error_msg = f"Failed to parse JSON response: {e}"
130130
logger.error(error_msg)
131-
raise ServerError(
131+
raise ClientError(
132132
status_code=response.status_code,
133133
message=error_msg,
134134
response_body=response.text,

agentrun/sandbox/api/sandbox_data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def _parse_success_response(response: httpx.Response) -> Dict[str, Any]:
138138
except ValueError as e:
139139
error_msg = f"Failed to parse JSON response: {e}"
140140
logger.error(error_msg)
141-
raise ServerError(
141+
raise ClientError(
142142
status_code=response.status_code,
143143
message=error_msg,
144144
response_body=response.text,

tests/unittests/sandbox/api/test_sandbox_data.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,13 +224,13 @@ def test_sync_success_code_body_is_not_treated_as_error(self):
224224
assert result == body
225225

226226
@respx.mock
227-
def test_sync_success_non_json_body_raises_server_error(self):
227+
def test_sync_success_non_json_body_raises_client_error(self):
228228
api = self.make_api()
229229
respx.get(f"{DATA_ENDPOINT}/sandboxes/sb-1/health").mock(
230230
return_value=httpx.Response(200, text="<html>ok</html>")
231231
)
232232

233-
with pytest.raises(ServerError) as exc_info:
233+
with pytest.raises(ClientError) as exc_info:
234234
api.get("/health")
235235

236236
error = exc_info.value

0 commit comments

Comments
 (0)