Skip to content

Commit 2313fa1

Browse files
committed
fix: add _parse_json_body_optional for callback failure API
1 parent 93f3f69 commit 2313fa1

File tree

1 file changed

+9
-18
lines changed
  • src/aws_durable_execution_sdk_python_testing/web

1 file changed

+9
-18
lines changed

src/aws_durable_execution_sdk_python_testing/web/handlers.py

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -81,25 +81,16 @@ def handle(self, parsed_route: Route, request: HTTPRequest) -> HTTPResponse:
8181
HTTPResponse: The HTTP response to send to the client
8282
"""
8383

84-
def _parse_json_body(
85-
self, request: HTTPRequest, required: bool = True
86-
) -> dict[str, Any]:
87-
"""Parse JSON body from HTTP request with validation.
88-
89-
Args:
90-
request: The HTTP request containing the JSON body
91-
required: Whether the request body is required
92-
93-
Returns:
94-
dict: The parsed JSON data, or empty dict if not required and missing
84+
def _parse_json_body(self, request: HTTPRequest) -> dict[str, Any]:
85+
"""Required body: raise if missing or invalid."""
86+
if not request.body:
87+
msg = "Request body is required"
88+
raise InvalidParameterValueException(msg)
89+
return self._parse_json_body_optional(request)
9590

96-
Raises:
97-
InvalidParameterValueException: If the request body is required but empty or invalid JSON
98-
"""
91+
def _parse_json_body_optional(self, request: HTTPRequest) -> dict[str, Any]:
92+
"""Optional body: return empty dict when missing, still raise on invalid JSON."""
9993
if not request.body:
100-
if required:
101-
msg = "Request body is required"
102-
raise InvalidParameterValueException(msg)
10394
return {}
10495

10596
# Handle both dict and bytes body types
@@ -695,7 +686,7 @@ def handle(self, parsed_route: Route, request: HTTPRequest) -> HTTPResponse:
695686
callback_route = cast(CallbackFailureRoute, parsed_route)
696687
callback_id: str = callback_route.callback_id
697688

698-
body_data: dict[str, Any] = self._parse_json_body(request, required=False)
689+
body_data: dict[str, Any] = self._parse_json_body_optional(request)
699690
callback_request: SendDurableExecutionCallbackFailureRequest = (
700691
SendDurableExecutionCallbackFailureRequest.from_dict(
701692
body_data, callback_id

0 commit comments

Comments
 (0)