{"record":{"id":"aa02b0b3e8708034","repo":"alibaba/nacos","slug":"http-response-status","errorCode":null,"errorMessage":"HTTP ${response.status}","messagePattern":"HTTP \\$\\{response\\.status\\}","errorType":"http","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"console-ui-next/src/lib/sse-utils.ts","lineNumber":95,"sourceCode":"\n  const controller = new AbortController();\n  const token = getAccessToken();\n\n  fetch(url, {\n    method: 'POST',\n    headers: {\n      'Content-Type': 'application/json',\n      Accept: 'text/event-stream',\n      ...(token\n        ? { Authorization: `Bearer ${token}`, AccessToken: token }\n        : {}),\n    },\n    body: JSON.stringify(payload),\n    signal: controller.signal,\n  })\n    .then((response) => {\n      if (!response.ok) {\n        throw new Error(`HTTP ${response.status}`);\n      }\n\n      const reader = response.body!.getReader();\n      const decoder = new TextDecoder();\n      let buffer = '';\n      let currentEventType = 'message';\n      let pendingData: T | null = null;\n\n      const read = (): Promise<void> =>\n        reader.read().then(({ done, value }) => {\n          if (done) {\n            onFinish?.();\n            return;\n          }\n\n          buffer += decoder.decode(value, { stream: true });\n          const lines = buffer.split('\\n');\n          buffer = lines.pop() || '';","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/console-ui-next/src/lib/sse-utils.ts#L77-L113","documentation":"Thrown by the SSE streaming fetch helper when the server returns a non-2xx HTTP status (response.ok is false). The error fires before any stream reading begins, so no SSE data is consumed. It surfaces the raw status code with no response body, making diagnosis of 401/403/422/500 cases dependent on network inspection.","triggerScenarios":"The backend rejects the SSE request due to an expired or missing Bearer token (401/403), a malformed payload failing server-side validation (400/422), or a transient server error (500/502/503). The endpoint URL or path is wrong (404).","commonSituations":"Long-running chat/completion sessions where the token expires mid-session. Proxy or gateway (nginx) timeouts returning 504. CORS misconfiguration returning a 0 or opaque status. Request payload exceeding a body-size limit (413).","solutions":["Check the status code value: 401/403 means refresh the auth token; 422 means fix the payload schema; 5xx means retry or contact backend.","Inspect the response body via browser DevTools Network tab, since the error message discards it.","For token-expiry, implement a token refresh interceptor before the SSE call and retry once.","Add response body extraction in the helper so the thrown error carries server-side detail."],"exampleFix":"// before\n.then((response) => {\n  if (!response.ok) {\n    throw new Error(`HTTP ${response.status}`);\n  }\n\n// after\n.then(async (response) => {\n  if (!response.ok) {\n    const detail = await response.text().catch(() => '');\n    throw new Error(`HTTP ${response.status}: ${detail}`);\n  }","handlingStrategy":"retry","validationCode":"async function safeSse(url, payload, token) {\n  const r = await fetch(url, { method:'POST', headers:{'Content-Type':'application/json', Authorization:`Bearer ${token}`}, body: JSON.stringify(payload) });\n  if (r.status === 401 || r.status === 403) { throw new Error('AUTH_EXPIRED'); }\n  if (!r.ok) { throw new Error(`HTTP ${r.status}: ${await r.text().catch(()=> '')}`); }\n  return r;\n}","typeGuard":"function isRetryableStatus(status: number): boolean {\n  return status === 429 || status >= 500;\n}","tryCatchPattern":"try { await streamSse(...); } catch (e) {\n  if (/HTTP 401|HTTP 403/.test(e.message)) { await refreshToken(); /* retry once */ }\n  else if (/HTTP 5\\d\\d/.test(e.message)) { scheduleRetry(); }\n  else { showError(e.message); }\n}","preventionTips":["Refresh token before long SSE sessions","Surface response body in the error","Retry 5xx with backoff","Verify endpoint path and CORS config"],"tags":["network","http","sse","fetch","authentication"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}