添加详细的客户端请求日志,便于排查问题

添加日志:
1. 请求URL和配置
2. 响应状态
3. 错误详情(包含响应body)
4. 捕获所有异常

帮助诊断:
- API_URL配置是否正确
- 请求是否发送成功
- 响应状态码和内容
- 具体的错误信息

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-10-30 14:51:05 +08:00
parent 79e0f542be
commit a5e5f289c1
+24 -4
View File
@@ -529,14 +529,24 @@ export const fetchConversations = async () => {
// 不再传递user参数,服务端会从JWT自动提取
});
return fetch(`${CHAT_CONFIG.API_URL}/conversations?${params}`, {
const url = `${CHAT_CONFIG.API_URL}/conversations?${params}`;
console.log('📋 [API Client] 获取会话列表:', { url, apiUrl: CHAT_CONFIG.API_URL });
return fetch(url, {
method: 'GET',
credentials: 'include', // 携带cookie
}).then(res => {
console.log('📋 [API Client] 会话列表响应:', { status: res.status, ok: res.ok });
if (!res.ok) {
throw new Error(`Failed to fetch conversations: ${res.status}`);
return res.text().then(text => {
console.error('❌ [API Client] 获取会话列表失败:', { status: res.status, body: text });
throw new Error(`Failed to fetch conversations: ${res.status} - ${text}`);
});
}
return res.json();
}).catch(err => {
console.error('❌ [API Client] 会话列表请求异常:', err);
throw err;
});
};
@@ -604,14 +614,24 @@ export const fetchChatList = async (conversationId: string) => {
* ```
*/
export const fetchAppParams = async () => {
return fetch(`${CHAT_CONFIG.API_URL}/parameters`, {
const url = `${CHAT_CONFIG.API_URL}/parameters`;
console.log('⚙️ [API Client] 获取应用参数:', { url, apiUrl: CHAT_CONFIG.API_URL });
return fetch(url, {
method: 'GET',
credentials: 'include', // 携带cookie
}).then(res => {
console.log('⚙️ [API Client] 应用参数响应:', { status: res.status, ok: res.ok });
if (!res.ok) {
throw new Error(`Failed to fetch app params: ${res.status}`);
return res.text().then(text => {
console.error('❌ [API Client] 获取应用参数失败:', { status: res.status, body: text });
throw new Error(`Failed to fetch app params: ${res.status} - ${text}`);
});
}
return res.json();
}).catch(err => {
console.error('❌ [API Client] 应用参数请求异常:', err);
throw err;
});
};