datawhalechina/hello-agents · error
服务器返回错误状态:${response.status}
Error message
服务器返回错误状态:${response.status} What it means
Generic task-submission guard in submitAndPollTask(): after fetch(url, body) for a long-running analysis task, a non-OK response throws this template with the status code. The task flow then never reaches the polling loop over /api/health/task_status/{task_id}. Any 4xx/5xx on the submit endpoint surfaces here.
Source
Thrown at Co-creation-projects/Shawnxyxy-HealthRecordAgent/frontend/app.js:530
agents.forEach((agent, i) => {
const li = agentContainer.children[i];
const statusSpan = li?.querySelector?.(".agent-progress-status");
if (statusSpan) statusSpan.textContent = getStatus(agent.key);
});
}
// 公共函数:提交任务并轮询状态
async function submitAndPollTask(url, body, agents, resultCard, reportDiv, analysisDiv, progressList, loadingText, doneText, errorText) {
reportDiv.innerHTML = "";
analysisDiv.innerText = loadingText;
progressList.classList.remove("hidden");
showAgentProgress(progressList, agents, () => "⏳ 执行中...");
resultCard.classList.add("hidden");
try {
const response = await fetch(url, body);
if (!response.ok) throw new Error(`服务器返回错误状态:${response.status}`);
const data = await response.json();
const taskId = data.task_id;
let taskStatus = await fetch(`${API_BASE}/api/health/task_status/${taskId}`).then(r => r.json());
while (taskStatus.state !== "completed") {
showAgentProgress(progressList, agents, agentKey => taskStatus.agents?.[agentKey] ?? "⏳ 执行中...");
await new Promise(res => setTimeout(res, 1000));
taskStatus = await fetch(`${API_BASE}/api/health/task_status/${taskId}`).then(r => r.json());
}
// 任务完成后刷新一次 agent 状态,保证 ReportAgent 也显示 completed
showAgentProgress(progressList, agents, agentKey => taskStatus.agents?.[agentKey] ?? "⏳ 执行中...");
// 显示最终报告
const summary = taskStatus.report?.report?.summary || "<p>❌ 未返回报告内容</p>";
reportDiv.innerHTML = typeof summary === "string" ? summary : JSON.stringify(summary, null, 2);
analysisDiv.innerText = doneText;
resultCard.classList.remove("hidden");
View on GitHub (pinned to 606a07d341)
Solutions
- Identify which submit URL failed (log url) and curl it with the same body to get the server's detail
- Read the response body before throwing and include it in the message so users see the backend reason
- If 502/503, confirm the FastAPI service and the task worker are both up
- If 413 via nginx, raise client_max_body_size
Example fix
// before
if (!response.ok) throw new Error(`服务器返回错误状态:${response.status}`);
// after
if (!response.ok) {
const data = await response.json().catch(() => ({}));
const detail = typeof data.detail === 'string' ? data.detail : JSON.stringify(data.detail || '');
throw new Error(`服务器返回错误状态:${response.status}${detail ? ':' + detail : ''}`);
} Defensive patterns
Strategy: retry
Try / catch
try { await submitAndPollTask(...); } catch (e) { resultCard.classList.remove('hidden'); analysisDiv.innerText = errorText + (e.message || ''); } Prevention
- Read and include the response body in thrown errors
- Add exponential backoff retry for transient 5xx on submit
- Cap the polling loop and handle state==='failed' as well as 'completed'
When it happens
Trigger: Submit endpoints (/api/health/analyze etc.) returning 422 for missing fields in body, 429 for rate limits, 500 when the agent orchestrator fails to enqueue, 502 when backend is down and a proxy answers. Note: fetch only rejects on network failure; HTTP errors land here.
Common situations: Backend agent queue full or LLM provider key missing so task creation 500s; request body schema changed between frontend and backend versions; reverse proxy body-size limit exceeded for large uploads.
Related errors
- 请求失败
- 研究请求失败,状态码:${response.status}
- HTTP ${res.status}
- 请求失败(${res.status})
- HTTP error: ${response.status}
AI-assisted analysis of datawhalechina/hello-agents@606a07d341 (2026-08-14).
Data as JSON: /api/errors/db6c3f10ecd4adfb.
Report an issue: GitHub.