mirror of
https://github.com/encounter/adk-python.git
synced 2026-07-09 18:19:28 -07:00
fix: Use json.dumps for error messages in SSE events
Co-authored-by: George Weale <gweale@google.com> PiperOrigin-RevId: 856737497
This commit is contained in:
committed by
Copybara-Service
parent
83d7bb6ef0
commit
6ad18cc2fc
@@ -1558,8 +1558,17 @@ class AdkWebServer:
|
||||
yield f"data: {sse_event}\n\n"
|
||||
except Exception as e:
|
||||
logger.exception("Error in event_generator: %s", e)
|
||||
# You might want to yield an error event here
|
||||
yield f'data: {{"error": "{str(e)}"}}\n\n'
|
||||
# Yield a proper Event object for the error
|
||||
error_event = Event(
|
||||
author="system",
|
||||
content=types.Content(
|
||||
role="model", parts=[types.Part(text=f"Error: {e}")]
|
||||
),
|
||||
)
|
||||
yield (
|
||||
"data:"
|
||||
f" {error_event.model_dump_json(by_alias=True, exclude_none=True)}\n\n"
|
||||
)
|
||||
|
||||
# Returns a streaming response with the proper media type for SSE
|
||||
return StreamingResponse(
|
||||
|
||||
Reference in New Issue
Block a user