{"record":{"id":"ea8f2f81c7351b06","repo":"datawhalechina/hello-agents","slug":"failed-to-submit-sentence-response-statustext","errorCode":null,"errorMessage":"Failed to submit sentence: ${response.statusText}","messagePattern":"Failed to submit sentence: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"Co-creation-projects/xujikai-SentenceExpandAgent/frontend/src/api/expand.ts","lineNumber":49,"sourceCode":"  }\n\n  return response.json();\n}\n\n/**\n * 提交用户扩写句子（手动模式）\n */\nexport async function submitSentence(request: SubmitRequest): Promise<AgentResponse> {\n  const response = await fetch(`${API_BASE_URL}/api/session/submit`, {\n    method: 'POST',\n    headers: {\n      'Content-Type': 'application/json',\n    },\n    body: JSON.stringify(request),\n  });\n\n  if (!response.ok) {\n    throw new Error(`Failed to submit sentence: ${response.statusText}`);\n  }\n\n  return response.json();\n}\n\n/**\n * 获取会话完整状态\n */\nexport async function getSession(sessionId: string): Promise<SessionState> {\n  const response = await fetch(`${API_BASE_URL}/api/session/${sessionId}`);\n\n  if (!response.ok) {\n    throw new Error(`Failed to get session: ${response.statusText}`);\n  }\n\n  return response.json();\n}\n","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/datawhalechina/hello-agents/blob/606a07d341a47be773fab7f4b71177f53f96b2c3/Co-creation-projects/xujikai-SentenceExpandAgent/frontend/src/api/expand.ts#L31-L67","documentation":"Thrown by submitSentence() in the SentenceExpandAgent frontend when POST /api/session/submit returns a non-OK status. This call carries a user's manual-mode expansion sentence, so the error means the backend rejected the submission — most often because the session referenced by the request no longer exists server-side. Like its sibling startSession, it reports only statusText, which can be empty.","triggerScenarios":"POST {API_BASE_URL}/api/session/submit with a SubmitRequest whose session_id is unknown/expired (404), whose sentence fails validation (422), when the backend LLM call fails (500), or when the backend is unreachable through the proxy (502).","commonSituations":"Backend restarted or uses in-memory session storage so all session_ids are lost; user leaves the page open past session TTL; sentence payload field names mismatched between frontend type and backend schema.","solutions":["Check the response status/body in DevTools: 404 on an existing session means server-side session store was reset — call startSession again to get a fresh session.","Verify the SubmitRequest field names/types match the backend endpoint schema exactly.","If sessions are in-memory on the backend, move them to a persistent store or add re-start logic on 404.","Improve the thrown error to include status and body (see exampleFix) since statusText is often blank."],"exampleFix":"// before\nif (!response.ok) {\n  throw new Error(`Failed to submit sentence: ${response.statusText}`);\n}\n\n// after\nif (!response.ok) {\n  const body = await response.text().catch(() => \"\");\n  throw new Error(`Failed to submit sentence: ${response.status} ${body.slice(0, 200)}`);\n}","handlingStrategy":"retry","validationCode":"if (!request.session_id) {\n  throw new Error('缺少 session_id，请先调用 startSession');\n}\nif (!request.sentence || !request.sentence.trim()) {\n  throw new Error('扩写句子不能为空');\n}","typeGuard":"function isSubmitRequest(r: unknown): r is SubmitRequest {\n  return typeof r === 'object' && r !== null\n    && typeof (r as SubmitRequest).session_id === 'string'\n    && typeof (r as SubmitRequest).sentence === 'string';\n}","tryCatchPattern":"try {\n  await submitSentence(request);\n} catch (err) {\n  if ((err as Error).message.includes('404')) {\n    // session lost server-side — restart and retry once\n    const fresh = await startSession(baseRequest);\n    await submitSentence({ ...request, session_id: fresh.session_id });\n  } else {\n    showError((err as Error).message);\n  }\n}","preventionTips":["Persist sessions server-side (DB/redis) instead of memory if users keep pages open.","Validate session_id presence and sentence non-empty before the POST.","Auto-restart the session on 404 instead of surfacing a dead-end error."],"tags":["http","fetch","session-expiry","api-client"],"backgroundTag":null,"analyzedSha":"606a07d341a47be773fab7f4b71177f53f96b2c3","analyzedAt":"2026-08-14T22:57:27.446Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}