Skip to content

Commit 921809e

Browse files
razor-xclaude
andauthored
feat: expose validation error messages on invalid input errors (#616)
Port the getValidationErrorMessages interface from the JavaScript SDK. SeamHttpInvalidInputError now carries the validation_errors from the API error response and exposes get_validation_error_messages(param_name), which returns the messages for a request parameter or an empty list when that parameter has none. Claude-Session: https://claude.ai/code/session_012RfnESV5b57QDoxMggXdM9 Co-authored-by: Claude <noreply@anthropic.com>
1 parent b1d514b commit 921809e

3 files changed

Lines changed: 29 additions & 1 deletion

File tree

‎seam/client.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ def _handle_error_response(self, response: Response):
146146
}
147147

148148
if error_type == "invalid_input":
149+
error_details["validation_errors"] = error.get("validation_errors")
149150
raise SeamHttpInvalidInputError(error_details, status_code, request_id)
150151

151152
raise SeamHttpApiError(error_details, status_code, request_id)

‎seam/exceptions.py‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Dict, Optional
1+
from typing import Any, Dict, List, Optional
22
from .resources import ActionAttempt
33

44

@@ -86,6 +86,19 @@ def __init__(
8686

8787
super().__init__(error, status_code, request_id)
8888
self.code = "invalid_input"
89+
self._validation_errors = error.get("validation_errors") or {}
90+
91+
def get_validation_error_messages(self, param_name: str) -> List[str]:
92+
"""
93+
The validation messages for a request parameter, or an empty list when
94+
that parameter has none.
95+
96+
:param param_name: Name of the request parameter
97+
:type param_name: str
98+
:rtype: List[str]
99+
"""
100+
101+
return self._validation_errors.get(param_name, {}).get("_errors", [])
89102

90103

91104
# Action Attempt

‎test/http_error_test.py‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,20 @@ def test_seam_http_throws_invalid_input_error(server):
4545
assert err.status_code == 400
4646
assert err.code == "invalid_input"
4747
assert err.request_id.startswith("request")
48+
assert err.get_validation_error_messages("device_ids") == [
49+
"Expected array, received number"
50+
]
51+
52+
53+
def test_seam_http_invalid_input_error_has_no_messages_for_unknown_param(server):
54+
endpoint, seed = server
55+
56+
seam = Seam(api_key=seed["seam_apikey1_token"], endpoint=endpoint)
57+
58+
with pytest.raises(SeamHttpInvalidInputError) as exc_info:
59+
seam.devices.list(device_ids=4242)
60+
61+
assert exc_info.value.get_validation_error_messages("non_existent_param") == []
4862

4963

5064
def test_seam_http_throws_http_error_on_non_standard_response(server):

0 commit comments

Comments
 (0)