Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
# 忽略所有数据库文件
*.db
*.db

# 忽略日志文件
logs/
*.log
server.log
47 changes: 47 additions & 0 deletions ERROR_HANDLING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# 错误处理增强说明

本次更新增强了系统的错误处理和日志记录功能,特别是针对"socket hang up"等网络连接问题。

## 主要改进

### 1. 服务器端增强 (server.js)

- **详细错误日志**:现在会记录完整的错误对象,包括:
- 错误消息、代码和堆栈
- 请求参数和配置
- 响应状态和数据
- 时间戳和重试信息

- **日志文件记录**:
- 所有API错误现在会写入 `logs/api-errors.log` 文件
- 包含完整的错误上下文和诊断信息

- **增强的错误响应**:
- API响应中包含更详细的错误信息
- 提供针对性的故障排除建议

### 2. 前端增强

- **增强的错误消息显示**:
- 添加了"显示详情"按钮,可展开查看完整错误信息
- 添加了"复制错误"按钮,方便分享错误信息

- **改进的CSS样式**:
- 更美观的错误消息提示
- 支持错误、成功、信息和警告四种消息类型
- 添加了消息动画效果

### 3. 使用方法

当遇到"socket hang up"或其他API调用错误时:

1. 错误消息会显示在页面右上角
2. 点击"显示详情"查看完整错误信息
3. 点击"复制错误"可复制错误详情用于报告问题
4. 查看 `logs/api-errors.log` 获取更多诊断信息

## 技术细节

- 错误日志会自动过滤敏感信息(如API密钥)
- 使用指数退避算法进行重试
- 针对不同类型的错误提供定制化的解决建议
7 changes: 7 additions & 0 deletions model-settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,12 @@
"model": "gemini-2.5-pro",
"apiKey": "xx"
},
"custom": {
"name": "自定义AI",
"apiUrl": "https://api.example.com/v1",
"model": "custom-model",
"apiKey": "",
"format": "openai"
},
"updatedAt": "2025-07-01T11:15:26.302Z"
}
262 changes: 262 additions & 0 deletions public/css/ai-settings.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,262 @@
/* AI设置模态框样式 */
.ai-settings-modal {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
z-index: 1000;
overflow-y: auto;
}

.ai-settings-modal.show {
display: flex;
align-items: center;
justify-content: center;
}

.ai-settings-content {
background-color: #fff;
border-radius: 8px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
width: 90%;
max-width: 600px;
max-height: 90vh;
overflow-y: auto;
animation: slideDown 0.3s ease;
}

.ai-settings-header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 15px 20px;
border-bottom: 1px solid #eee;
}

.ai-settings-header h3 {
margin: 0;
font-size: 18px;
color: #333;
}

.ai-settings-close {
background: none;
border: none;
font-size: 24px;
cursor: pointer;
color: #999;
}

.ai-settings-close:hover {
color: #333;
}

.ai-settings-body {
padding: 20px;
}

.settings-group {
margin-bottom: 20px;
}

.settings-group label {
display: block;
margin-bottom: 8px;
font-weight: 500;
color: #333;
}

.settings-group input[type="text"],
.settings-group select,
.settings-group textarea {
width: 100%;
padding: 10px;
border: 1px solid #ddd;
border-radius: 4px;
font-size: 14px;
}

.settings-group textarea {
min-height: 120px;
resize: vertical;
}

.settings-actions {
display: flex;
justify-content: flex-end;
margin-top: 20px;
gap: 10px;
}

.save-settings-btn,
.reset-settings-btn,
.delete-item-btn {
padding: 8px 16px;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 14px;
display: flex;
align-items: center;
gap: 5px;
}

.save-settings-btn {
background-color: #4CAF50;
color: white;
}

.reset-settings-btn {
background-color: #f0f0f0;
color: #333;
}

.delete-item-btn {
background-color: #f44336;
color: white;
margin-right: auto;
}

.save-settings-btn:hover {
background-color: #45a049;
}

.reset-settings-btn:hover {
background-color: #e0e0e0;
}

.delete-item-btn:hover {
background-color: #d32f2f;
}

.custom-date-range {
margin-top: 10px;
}

.date-inputs {
display: flex;
gap: 10px;
}

.date-inputs > div {
flex: 1;
}

/* 搜索下拉框样式 */
.searchable-select {
position: relative;
}

.group-search-input {
width: 100%;
padding: 10px;
border: 1px solid #ddd;
border-radius: 4px;
margin-bottom: 8px;
font-size: 14px;
}

.search-results-count {
position: absolute;
right: 10px;
top: 10px;
font-size: 12px;
color: #666;
background-color: #f0f0f0;
padding: 2px 6px;
border-radius: 10px;
}

/* 全局设置区域样式 */
.global-settings-section {
margin-top: 30px;
padding-top: 20px;
border-top: 1px solid #eee;
}

.global-settings-section h4 {
margin-top: 0;
margin-bottom: 15px;
font-size: 16px;
color: #333;
}

/* 复选框组样式 */
.checkbox-group {
display: flex;
align-items: center;
margin-bottom: 15px;
}

.checkbox-label {
display: flex;
align-items: center;
cursor: pointer;
user-select: none;
}

.checkbox-label input[type="checkbox"] {
margin-right: 8px;
cursor: pointer;
}

.checkbox-text {
font-weight: normal;
margin-right: 5px;
}

/* 提示图标样式 */
.tooltip-icon {
display: inline-block;
width: 16px;
height: 16px;
background-color: #f0f0f0;
border-radius: 50%;
text-align: center;
line-height: 16px;
font-size: 12px;
color: #666;
cursor: help;
margin-left: 5px;
}

.tooltip-icon:hover {
background-color: #e0e0e0;
}

/* 提示框样式 */
.settings-tooltip {
position: absolute;
background-color: #333;
color: #fff;
padding: 5px 10px;
border-radius: 4px;
font-size: 12px;
z-index: 1100;
max-width: 200px;
box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

.settings-tooltip::before {
content: '';
position: absolute;
top: -5px;
left: 10px;
border-left: 5px solid transparent;
border-right: 5px solid transparent;
border-bottom: 5px solid #333;
}

@keyframes slideDown {
from {
transform: translateY(-20px);
opacity: 0;
}
to {
transform: translateY(0);
opacity: 1;
}
}
Loading