{"record":{"id":"ad98696624867354","repo":"alibaba/nacos","slug":"http-response-status-ad9869","errorCode":null,"errorMessage":"HTTP ${response.status}","messagePattern":"HTTP \\$\\{response\\.status\\}","errorType":"http","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"console-ui-next/src/pages/promptManagement/components/CreatePromptDialog.tsx","lineNumber":146,"sourceCode":"    } catch (err: unknown) {\n      const msg = err instanceof Error ? err.message : 'Failed to create prompt';\n      setError(msg);\n    } finally { setLoading(false); }\n  }, [promptKey, template, variables, variableDefaults, variableDescriptions, commitMsg, description, bizTags, namespaceId, t, handleClose, onSuccess]);\n\n  // SSE AI Optimize\n  const handleStartOptimize = () => {\n    if (!template.trim()) return;\n    setOptimizing(true); setOptimizeStream(''); setOptimizedResult(null); setOptimizeError(null);\n    const ctxPath = window.location.pathname.replace(/\\/(next|legacy)(\\/.*)?$/, '/') || '/';\n    const url = `${window.location.origin}${ctxPath}v3/console/copilot/prompt/optimize`;\n    const token = getAccessToken();\n    fetch(url, {\n      method: 'POST',\n      headers: { 'Content-Type': 'application/json', Accept: 'text/event-stream', ...(token ? { Authorization: `Bearer ${token}`, AccessToken: token } : {}) },\n      body: JSON.stringify({ prompt: template, optimizationGoal: optimizeGoal }),\n    }).then((response) => {\n      if (!response.ok) throw new Error(`HTTP ${response.status}`);\n      const reader = response.body!.getReader();\n      const decoder = new TextDecoder();\n      let buffer = '', accumulated = '';\n      const read = (): Promise<void> => reader.read().then(({ done, value }) => {\n        if (done) { setOptimizing(false); setOptimizedResult(accumulated || null); return; }\n        buffer += decoder.decode(value, { stream: true });\n        const lines = buffer.split('\\n'); buffer = lines.pop() || '';\n        lines.forEach((line) => {\n          if (line.startsWith('data:')) {\n            try {\n              const data = JSON.parse(line.substring(5).trim());\n              const typeStr = data.type?.code || data.type || 'CONTENT';\n              if (typeStr === 'CONTENT') { accumulated += data.chunk || ''; setOptimizeStream(accumulated); }\n              else if (typeStr === 'DONE' || data.done) { setOptimizing(false); setOptimizedResult(accumulated || null); }\n              else if (typeStr === 'error') { setOptimizing(false); setOptimizeError(data.message || 'Error'); }\n            } catch { /* ignore */ }\n          }\n        });","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/console-ui-next/src/pages/promptManagement/components/CreatePromptDialog.tsx#L128-L164","documentation":"Thrown by CreatePromptDialog's inline SSE optimize handler when POST /v3/console/copilot/prompt/optimize returns non-2xx. Same endpoint and same guard as the prompt-detail optimize handler, but invoked from the prompt-management create/edit dialog. The thrown value is the bare HTTP status.","triggerScenarios":"Optimize clicked in the create-prompt dialog with an invalid/expired token (401/403), endpoint missing (404), or AI backend error (500). Template whitespace-only is already guarded before fetch.","commonSituations":"Token expired while the create-prompt dialog was open. AI/copilot module disabled. User role lacks AI WRITE permission. Transient 5xx during model inference.","solutions":["Re-authenticate and retry if the token expired.","Confirm copilot module + AI model are configured on the server.","Map the status code to a user-facing message (401/403 auth, 404 missing, 500 server).","Add a bounded retry with backoff for transient 5xx responses."],"exampleFix":"// before\n}).then((response) => {\n  if (!response.ok) throw new Error(`HTTP ${response.status}`);\n\n// after\n}).then(async (response) => {\n  if (!response.ok) {\n    const body = await response.text().catch(() => response.statusText);\n    throw new Error(`Prompt optimize failed (${response.status}): ${body}`);\n  }","handlingStrategy":"try-catch","validationCode":"function canStartOptimize(token: string | null, template: string): boolean {\n  return !!token && !!template.trim();\n}","typeGuard":null,"tryCatchPattern":".then(async (response) => {\n  if (!response.ok) {\n    if (response.status === 401 || response.status === 403) { await reAuthenticate(); }\n    const body = await response.text().catch(() => response.statusText);\n    throw new Error(`Optimize failed (${response.status}): ${body}`);\n  }\n  return response;\n}).catch((err) => { setOptimizing(false); setOptimizeError(err.message || 'Request failed'); });","preventionTips":["Validate the token and template are present before opening the optimize stream.","Handle 401/403 by triggering re-authentication.","Provide a retry affordance for transient 5xx errors.","Share the optimize-handler logic between CreatePromptDialog and promptDetail to keep behavior consistent."],"tags":["sse","copilot","prompt-optimize","typescript","network","react","dialog"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}