Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions src/bedrock_agentcore/runtime/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,16 @@ async def _handle_invocation(self, request):

try:
payload = await request.json()
except json.JSONDecodeError as e:
duration = time.time() - start_time
self.logger.warning("Invalid JSON in request (%.3fs): %s", duration, e)
return JSONResponse({"error": "Invalid JSON", "details": str(e)}, status_code=400)
except UnicodeDecodeError as e:
duration = time.time() - start_time
self.logger.warning("Invalid encoding in request (%.3fs): %s", duration, e)
return JSONResponse({"error": "Invalid encoding", "details": str(e)}, status_code=400)

try:
self.logger.debug("Processing invocation request")

if self.debug:
Expand Down Expand Up @@ -581,15 +591,6 @@ async def _handle_invocation(self, request):
# Use safe serialization for consistency with streaming paths
safe_json_string = self._safe_serialize_to_json_string(result)
return Response(safe_json_string, media_type="application/json")

except json.JSONDecodeError as e:
duration = time.time() - start_time
self.logger.warning("Invalid JSON in request (%.3fs): %s", duration, e)
return JSONResponse({"error": "Invalid JSON", "details": str(e)}, status_code=400)
except UnicodeDecodeError as e:
duration = time.time() - start_time
self.logger.warning("Invalid encoding in request (%.3fs): %s", duration, e)
return JSONResponse({"error": "Invalid encoding", "details": str(e)}, status_code=400)
except HTTPException as e:
duration = time.time() - start_time
# Use error level for 5xx to match the generic Exception handler's severity,
Expand Down
Loading