{"record":{"id":"604aee7face5bb07","repo":"yikart/AiToEarn","slug":"http-error-status-response-status-604aee","errorCode":null,"errorMessage":"HTTP error! status: ${response.status}","messagePattern":"HTTP error! status: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"project/aitoearn-electron/src/views/task/task.tsx","lineNumber":1036,"sourceCode":"  const testSseFunc = async (item: any) => {\n    try {\n      setHtmlContent(''); // 清空之前的内容\n      setHtmlModalVisible(true); // 显示模态框\n      const response = await fetch(\n        import.meta.env.VITE_APP_URL + '/tools/ai/article/html/sse',\n        {\n          method: 'POST',\n          headers: {\n            'Content-Type': 'application/json',\n          },\n          body: JSON.stringify({\n            content: '生成一个卡通人物介绍页 带有图片 小红书图文流光卡片样式',\n          }),\n        },\n      );\n\n      if (!response.ok) {\n        throw new Error(`HTTP error! status: ${response.status}`);\n      }\n\n      const reader = response.body?.getReader();\n      if (!reader) {\n        throw new Error('无法获取响应流');\n      }\n\n      let htmlString = '';\n      let isCollectingHtml = false;\n      let buffer = '';\n\n      // 处理响应流\n      while (true) {\n        const { done, value } = await reader.read();\n        if (done) {\n          console.log('流读取完成');\n          setHtmlContent(htmlString); // 设置最终的 HTML 内容\n          break;","sourceCodeStart":1018,"sourceCodeEnd":1054,"githubUrl":"https://github.com/yikart/AiToEarn/blob/d3aa8bea5b146a8675607cf0144d891aad3e9683/project/aitoearn-electron/src/views/task/task.tsx#L1018-L1054","documentation":"testSseFunc in the electron task view performs a raw fetch to an SSE/generation endpoint and throws `HTTP error! status: ${response.status}` when response.ok is false. It's a debug/test function for the SSE streaming flow, so it surfaces the raw HTTP status without parsing any API error body.","triggerScenarios":"The fetch to the task/generation API returns non-2xx: invalid or missing API key/token (401), wrong base URL or environment (aitoearn.cn vs aitoearn.ai mismatch), 404 route, 429 rate limit, or 5xx from the backend.","commonSituations":"Testing SSE with a stale/expired token, pointing the dev build at the wrong environment so the API key doesn't match the server, or the backend route changed/deprecated.","solutions":["Log the response body (await response.text()) to get the API's actual error message before/instead of the generic throw","Verify auth headers (API key / Authorization) are present and match the environment of the endpoint URL","Check the endpoint URL and that the route still exists; confirm expected status with curl","Add retry with backoff for 429/5xx"],"exampleFix":"// before\nif (!response.ok) {\n  throw new Error(`HTTP error! status: ${response.status}`);\n}\n// after\nif (!response.ok) {\n  const body = await response.text();\n  throw new Error(`HTTP error! status: ${response.status}, body: ${body}`);\n}","handlingStrategy":"retry","validationCode":"function validateSseRequest(url: string, headers: Record<string,string>) {\n  if (!url.startsWith('https://')) throw new Error('endpoint must be https')\n  if (!headers.Authorization && !headers['api-key']) throw new Error('missing auth header')\n  if (url.includes('aitoearn.cn') === url.includes('aitoearn.ai')) throw new Error('ambiguous environment URL')\n}","typeGuard":"function hasReadableBody(r: Response): boolean { return r.ok && r.body !== null }","tryCatchPattern":"try {\n  await testSseFunc()\n} catch (e) {\n  const m = /HTTP error! status: (\\d+)/.exec(e.message)\n  if (m && ['429','502','503','504'].includes(m[1])) return retryWithBackoff(testSseFunc)\n  if (m && m[1] === '401') return promptRelogin()\n  throw e\n}","preventionTips":["Log response.text() on failure to capture the API's real error message","Keep API keys and endpoint environments matched (cn key ⇒ cn URL, ai key ⇒ ai URL)","Refresh tokens before long-running test sessions","Retry 429/5xx with backoff; never retry 401/403/404 blindly"],"tags":["http","sse","network","electron"],"backgroundTag":"http-error-status","analyzedSha":"d3aa8bea5b146a8675607cf0144d891aad3e9683","analyzedAt":"2026-08-31T14:19:24.185Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}