Skip to content

Commit 063a8f8

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

1 file changed

Lines changed: 21 additions & 10 deletions

File tree

  • src/aws_durable_execution_sdk_python_testing/web

src/aws_durable_execution_sdk_python_testing/web/handlers.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,25 +81,36 @@ 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]:
84+
def _parse_json_body(self, request: HTTPRequest) -> dict[str, Any]:
8785
"""Parse JSON body from HTTP request with validation.
8886
8987
Args:
9088
request: The HTTP request containing the JSON body
91-
required: Whether the request body is required
9289
9390
Returns:
94-
dict: The parsed JSON data, or empty dict if not required and missing
91+
dict: The parsed JSON data
9592
9693
Raises:
97-
InvalidParameterValueException: If the request body is required but empty or invalid JSON
94+
InvalidParameterValueException: If the request body is empty
95+
"""
96+
if not request.body:
97+
msg = "Request body is required"
98+
raise InvalidParameterValueException(msg)
99+
return self._parse_json_body_optional(request)
100+
101+
def _parse_json_body_optional(self, request: HTTPRequest) -> dict[str, Any]:
102+
"""Parse JSON body from HTTP request with validation.
103+
104+
Args:
105+
request: The HTTP request containing the JSON body
106+
107+
Returns:
108+
dict: The parsed JSON data
109+
110+
Raises:
111+
InvalidParameterValueException: If the request body is invalid JSON
98112
"""
99113
if not request.body:
100-
if required:
101-
msg = "Request body is required"
102-
raise InvalidParameterValueException(msg)
103114
return {}
104115

105116
# Handle both dict and bytes body types
@@ -695,7 +706,7 @@ def handle(self, parsed_route: Route, request: HTTPRequest) -> HTTPResponse:
695706
callback_route = cast(CallbackFailureRoute, parsed_route)
696707
callback_id: str = callback_route.callback_id
697708

698-
body_data: dict[str, Any] = self._parse_json_body(request, required=False)
709+
body_data: dict[str, Any] = self._parse_json_body_optional(request)
699710
callback_request: SendDurableExecutionCallbackFailureRequest = (
700711
SendDurableExecutionCallbackFailureRequest.from_dict(
701712
body_data, callback_id

0 commit comments

Comments
 (0)