yikart/AiToEarn · error · Error

HTTP error! status

Error message

HTTP error! status: ${response.status}

What it means

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.

Solutions

  1. Log the response body (await response.text()) to get the API's actual error message before/instead of the generic throw
  2. Verify auth headers (API key / Authorization) are present and match the environment of the endpoint URL
  3. Check the endpoint URL and that the route still exists; confirm expected status with curl
  4. Add retry with backoff for 429/5xx

Example fix

// before
if (!response.ok) {
  throw new Error(`HTTP error! status: ${response.status}`);
}
// after
if (!response.ok) {
  const body = await response.text();
  throw new Error(`HTTP error! status: ${response.status}, body: ${body}`);
}
Defensive patterns

Strategy: retry

Validate before calling

function validateSseRequest(url: string, headers: Record<string,string>) {
  if (!url.startsWith('https://')) throw new Error('endpoint must be https')
  if (!headers.Authorization && !headers['api-key']) throw new Error('missing auth header')
  if (url.includes('aitoearn.cn') === url.includes('aitoearn.ai')) throw new Error('ambiguous environment URL')
}

Type guard

function hasReadableBody(r: Response): boolean { return r.ok && r.body !== null }

Try / catch

try {
  await testSseFunc()
} catch (e) {
  const m = /HTTP error! status: (\d+)/.exec(e.message)
  if (m && ['429','502','503','504'].includes(m[1])) return retryWithBackoff(testSseFunc)
  if (m && m[1] === '401') return promptRelogin()
  throw e
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of yikart/AiToEarn@d3aa8bea5b (2026-08-31). Data as JSON: /api/errors/604aee7face5bb07. Report an issue: GitHub.

Appendix: source

Thrown at project/aitoearn-electron/src/views/task/task.tsx:1036

  const testSseFunc = async (item: any) => {
    try {
      setHtmlContent(''); // 清空之前的内容
      setHtmlModalVisible(true); // 显示模态框
      const response = await fetch(
        import.meta.env.VITE_APP_URL + '/tools/ai/article/html/sse',
        {
          method: 'POST',
          headers: {
            'Content-Type': 'application/json',
          },
          body: JSON.stringify({
            content: '生成一个卡通人物介绍页 带有图片 小红书图文流光卡片样式',
          }),
        },
      );

      if (!response.ok) {
        throw new Error(`HTTP error! status: ${response.status}`);
      }

      const reader = response.body?.getReader();
      if (!reader) {
        throw new Error('无法获取响应流');
      }

      let htmlString = '';
      let isCollectingHtml = false;
      let buffer = '';

      // 处理响应流
      while (true) {
        const { done, value } = await reader.read();
        if (done) {
          console.log('流读取完成');
          setHtmlContent(htmlString); // 设置最终的 HTML 内容
          break;

View on GitHub (pinned to d3aa8bea5b)