fix: 修复 API 响应 body stream 重复读取错误

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
dreamhunter2333andClaude Opus 4.5 committed 2025-12-27 11:29:41 +08:00
1 parent 6713f240ba
commit 990528da37
1 file changed
+7 -2
+7 -2
View File
@@ -48,11 +48,16 @@ async function responseInterceptor(response: Response): Promise<any> {
if (!response.ok) {
let errorMessage: string
// 先读取为文本,避免 body stream already read 错误
const responseText = await response.text()
try {
const errorData = await response.json()
// 尝试解析为 JSON
const errorData = JSON.parse(responseText)
errorMessage = errorData.message || errorData.error || JSON.stringify(errorData)
} catch {
errorMessage = await response.text() || `请求失败: ${response.status}`
// 不是 JSON,直接使用文本
errorMessage = responseText || `请求失败: ${response.status}`
}
const error = new ApiError(errorMessage, response.status)