修复删除对话时报500错误的问题
问题:
- 删除对话实际成功但前端报错"Failed to delete conversation: 500"
- Dify删除API返回的可能不是JSON格式(空响应或文本)
- 原代码直接调用response.json()导致解析失败抛出异常
修复:
1. 添加Content-Type检查,只有JSON才解析
2. 非JSON响应直接返回成功标识 { result: 'success' }
3. 添加详细日志方便调试
现在删除对话能正确显示成功,无需刷新页面
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -202,11 +202,35 @@ export const difyClient = {
|
||||
// user 字段已移除,后端会自动从 JWT 中提取 username
|
||||
const body = {};
|
||||
|
||||
console.log('🗑️ [DifyClient] 删除会话:', conversationId);
|
||||
|
||||
const response = await difyFetch(`conversations/${conversationId}`, {
|
||||
method: 'DELETE',
|
||||
body: JSON.stringify(body),
|
||||
}, jwt);
|
||||
return response.json();
|
||||
|
||||
console.log('🗑️ [DifyClient] 删除会话响应:', {
|
||||
status: response.status,
|
||||
statusText: response.statusText,
|
||||
contentType: response.headers.get('Content-Type')
|
||||
});
|
||||
|
||||
// 检查响应的Content-Type
|
||||
const contentType = response.headers.get('Content-Type');
|
||||
|
||||
// 如果是JSON响应,解析JSON
|
||||
if (contentType && contentType.includes('application/json')) {
|
||||
const data = await response.json();
|
||||
console.log('🗑️ [DifyClient] 删除会话JSON响应:', data);
|
||||
return data;
|
||||
}
|
||||
|
||||
// 如果不是JSON,返回成功标识
|
||||
const text = await response.text();
|
||||
console.log('🗑️ [DifyClient] 删除会话文本响应:', text);
|
||||
|
||||
// 返回标准成功响应
|
||||
return { result: 'success' };
|
||||
},
|
||||
|
||||
// 更新消息反馈
|
||||
|
||||
Reference in New Issue
Block a user