Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 7 additions & 1 deletion backend/routes/history_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,13 @@ def create_history():
}
"""
try:
data = request.get_json()
data = request.get_json(silent=True)
if not isinstance(data, dict):
return api_error_response(
validation_error("请求体必须是 JSON 对象", "请提供包含 topic 和 outline 的 JSON 对象。"),
context={"endpoint": "/api/history"},
)

topic = data.get('topic')
outline = data.get('outline')
task_id = data.get('task_id')
Expand Down
14 changes: 14 additions & 0 deletions tests/errors_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,20 @@ def test_outline_missing_topic_returns_structured_error(client):
assert data["error_message"]


def test_create_history_null_json_returns_structured_error(client):
response = client.post(
"/api/history",
data="null",
content_type="application/json",
)
data = response.get_json()

assert response.status_code == 400
assert data["success"] is False
assert data["error"]["code"] == "INVALID_REQUEST"
assert data["error"]["detail"] == "请求体必须是 JSON 对象"


def test_sse_error_event_is_structured():
data = _normalize_sse_error(
"error",
Expand Down