{"record":{"id":"db6c3f10ecd4adfb","repo":"datawhalechina/hello-agents","slug":"response-status-db6c3f","errorCode":null,"errorMessage":"服务器返回错误状态：${response.status}","messagePattern":"服务器返回错误状态：(.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"Co-creation-projects/Shawnxyxy-HealthRecordAgent/frontend/app.js","lineNumber":530,"sourceCode":"\n    agents.forEach((agent, i) => {\n        const li = agentContainer.children[i];\n        const statusSpan = li?.querySelector?.(\".agent-progress-status\");\n        if (statusSpan) statusSpan.textContent = getStatus(agent.key);\n    });\n}\n\n// 公共函数：提交任务并轮询状态\nasync function submitAndPollTask(url, body, agents, resultCard, reportDiv, analysisDiv, progressList, loadingText, doneText, errorText) {\n    reportDiv.innerHTML = \"\";\n    analysisDiv.innerText = loadingText;\n    progressList.classList.remove(\"hidden\");\n    showAgentProgress(progressList, agents, () => \"⏳ 执行中...\");\n    resultCard.classList.add(\"hidden\");\n\n    try {\n        const response = await fetch(url, body);\n        if (!response.ok) throw new Error(`服务器返回错误状态：${response.status}`);\n\n        const data = await response.json();\n        const taskId = data.task_id;\n\n        let taskStatus = await fetch(`${API_BASE}/api/health/task_status/${taskId}`).then(r => r.json());\n        while (taskStatus.state !== \"completed\") {\n            showAgentProgress(progressList, agents, agentKey => taskStatus.agents?.[agentKey] ?? \"⏳ 执行中...\");\n            await new Promise(res => setTimeout(res, 1000));\n            taskStatus = await fetch(`${API_BASE}/api/health/task_status/${taskId}`).then(r => r.json());\n        }\n        // 任务完成后刷新一次 agent 状态，保证 ReportAgent 也显示 completed\n        showAgentProgress(progressList, agents, agentKey => taskStatus.agents?.[agentKey] ?? \"⏳ 执行中...\");\n        // 显示最终报告\n        const summary = taskStatus.report?.report?.summary || \"<p>❌ 未返回报告内容</p>\";\n        reportDiv.innerHTML = typeof summary === \"string\" ? summary : JSON.stringify(summary, null, 2);\n        analysisDiv.innerText = doneText;\n        resultCard.classList.remove(\"hidden\");\n","sourceCodeStart":512,"sourceCodeEnd":548,"githubUrl":"https://github.com/datawhalechina/hello-agents/blob/606a07d341a47be773fab7f4b71177f53f96b2c3/Co-creation-projects/Shawnxyxy-HealthRecordAgent/frontend/app.js#L512-L548","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nif (!response.ok) throw new Error(`服务器返回错误状态：${response.status}`);\n\n// after\nif (!response.ok) {\n    const data = await response.json().catch(() => ({}));\n    const detail = typeof data.detail === 'string' ? data.detail : JSON.stringify(data.detail || '');\n    throw new Error(`服务器返回错误状态：${response.status}${detail ? '：' + detail : ''}`);\n}","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { await submitAndPollTask(...); } catch (e) { resultCard.classList.remove('hidden'); analysisDiv.innerText = errorText + (e.message || ''); }","preventionTips":["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'"],"tags":["fetch","http","task-queue","polling"],"backgroundTag":null,"analyzedSha":"606a07d341a47be773fab7f4b71177f53f96b2c3","analyzedAt":"2026-08-14T22:57:27.446Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}