flipped-aurora/gin-vue-admin · error · Error
LLM request failed
Error message
LLM request failed
What it means
streamLLMRequest first tries to consume the response as an SSE stream; if the Content-Type is not text/event-stream it falls back to normal JSON parsing. If the JSON body has a non-zero code, it throws 'LLM request failed' with the server's msg if present.
Source
Thrown at web/src/api/autoCode.js:167
})
if (!response.ok) {
throw await buildFetchError(response)
}
const contentType = String(
response.headers.get('content-type') || ''
).toLowerCase()
// 上游非 SSE:降级为普通 JSON 解析
if (!contentType.includes('text/event-stream') || !response.body) {
console.warn(
'[SSE] 响应非 SSE 格式,Content-Type:',
contentType,
'| 降级为普通 JSON 解析'
)
const body = await parseFetchBody(response)
if (typeof body?.code !== 'undefined' && body.code !== 0) {
throw new Error(body.msg || 'LLM request failed')
}
return body
}
console.debug('[SSE] 已进入流式读取模式')
const reader = response.body.getReader()
const decoder = new TextDecoder()
let buffer = ''
let done = false
while (!done) {
const result = await reader.read()
done = result.done
if (done) break
buffer += decoder.decode(result.value, { stream: true })
const lines = buffer.split('\n')
// 保留最后一条可能不完整的行View on GitHub (pinned to 3136500ef3)
Solutions
- Inspect body.msg from the response to find the real server-side error (often auth or permission)
- Confirm the request URL targets the LLM SSE endpoint and the user has API/casbin permission for it
- Check server logs at the corresponding handler for the failure reason
- Ensure proxies/nginx pass through the text/event-stream Content-Type
Defensive patterns
Strategy: validation
Validate before calling
const ct = response.headers.get('Content-Type') || ''
if (!ct.includes('text/event-stream') && !ct.includes('application/json')) {
throw new Error(`Unexpected content-type: ${ct}`)
} Type guard
function isApiErrorBody(body) {
return typeof body?.code !== 'undefined' && body.code !== 0
} Try / catch
try {
const body = await streamLLMRequest(url, options)
} catch (e) {
if (e.message === 'LLM request failed') {
ElMessage.error('请求被服务端拒绝,请检查登录态与权限')
}
} Prevention
- Confirm the user's token/casbin permission before calling the SSE endpoint
- Log the response Content-Type and body when falling back to JSON parsing
- Keep the {code,msg,data} envelope consistent so msg is always present
When it happens
Trigger: The fetch response Content-Type is not SSE, the body parses as JSON with body.code !== 0, and body.msg is empty/undefined so the fallback message is thrown.
Common situations: Backend returns a standard {code,msg} error envelope (auth failure, Casbin denial, validation error) instead of an SSE stream; wrong route hit returning JSON; proxy strips the SSE Content-Type.
Related errors
- LLM stream failed
- 上游大模型流式服务返回非 2xx: status=%d content-type=%s read-body-err=%w
- 调用上游大模型流式服务失败: %w
- LLM stream request timed out
- 上游大模型流式服务返回非 2xx: status=%d content-type=%s read-body-err=%w
AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31).
Data as JSON: /api/errors/d4af79e27f70e8d6.
Report an issue: GitHub.