alibaba/nacos · error · Error

HTTP ${response.status}

Error message

HTTP ${response.status}

What it means

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.

Source

Thrown at console-ui-next/src/pages/promptManagement/components/CreatePromptDialog.tsx:146

    } catch (err: unknown) {
      const msg = err instanceof Error ? err.message : 'Failed to create prompt';
      setError(msg);
    } finally { setLoading(false); }
  }, [promptKey, template, variables, variableDefaults, variableDescriptions, commitMsg, description, bizTags, namespaceId, t, handleClose, onSuccess]);

  // SSE AI Optimize
  const handleStartOptimize = () => {
    if (!template.trim()) return;
    setOptimizing(true); setOptimizeStream(''); setOptimizedResult(null); setOptimizeError(null);
    const ctxPath = window.location.pathname.replace(/\/(next|legacy)(\/.*)?$/, '/') || '/';
    const url = `${window.location.origin}${ctxPath}v3/console/copilot/prompt/optimize`;
    const token = getAccessToken();
    fetch(url, {
      method: 'POST',
      headers: { 'Content-Type': 'application/json', Accept: 'text/event-stream', ...(token ? { Authorization: `Bearer ${token}`, AccessToken: token } : {}) },
      body: JSON.stringify({ prompt: template, optimizationGoal: optimizeGoal }),
    }).then((response) => {
      if (!response.ok) throw new Error(`HTTP ${response.status}`);
      const reader = response.body!.getReader();
      const decoder = new TextDecoder();
      let buffer = '', accumulated = '';
      const read = (): Promise<void> => reader.read().then(({ done, value }) => {
        if (done) { setOptimizing(false); setOptimizedResult(accumulated || null); return; }
        buffer += decoder.decode(value, { stream: true });
        const lines = buffer.split('\n'); buffer = lines.pop() || '';
        lines.forEach((line) => {
          if (line.startsWith('data:')) {
            try {
              const data = JSON.parse(line.substring(5).trim());
              const typeStr = data.type?.code || data.type || 'CONTENT';
              if (typeStr === 'CONTENT') { accumulated += data.chunk || ''; setOptimizeStream(accumulated); }
              else if (typeStr === 'DONE' || data.done) { setOptimizing(false); setOptimizedResult(accumulated || null); }
              else if (typeStr === 'error') { setOptimizing(false); setOptimizeError(data.message || 'Error'); }
            } catch { /* ignore */ }
          }
        });

View on GitHub (pinned to 9b989acdf1)

Solutions

  1. Re-authenticate and retry if the token expired.
  2. Confirm copilot module + AI model are configured on the server.
  3. Map the status code to a user-facing message (401/403 auth, 404 missing, 500 server).
  4. Add a bounded retry with backoff for transient 5xx responses.

Example fix

// before
}).then((response) => {
  if (!response.ok) throw new Error(`HTTP ${response.status}`);

// after
}).then(async (response) => {
  if (!response.ok) {
    const body = await response.text().catch(() => response.statusText);
    throw new Error(`Prompt optimize failed (${response.status}): ${body}`);
  }
Defensive patterns

Strategy: try-catch

Validate before calling

function canStartOptimize(token: string | null, template: string): boolean {
  return !!token && !!template.trim();
}

Try / catch

.then(async (response) => {
  if (!response.ok) {
    if (response.status === 401 || response.status === 403) { await reAuthenticate(); }
    const body = await response.text().catch(() => response.statusText);
    throw new Error(`Optimize failed (${response.status}): ${body}`);
  }
  return response;
}).catch((err) => { setOptimizing(false); setOptimizeError(err.message || 'Request failed'); });

Prevention

When it happens

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

Common situations: Token expired while the create-prompt dialog was open. AI/copilot module disabled. User role lacks AI WRITE permission. Transient 5xx during model inference.

Related errors


AI-assisted analysis of alibaba/nacos@9b989acdf1 (2026-08-14). Data as JSON: /api/errors/ad98696624867354. Report an issue: GitHub.