refactor: 清理 AI 客户端死代码并统一错误处理

- 删除未使用的 OpenAiCompatibleClient,DTO 抽离到 ai_contracts.cs
- 新增 AiHttpResponseGuard 统一 LLM/VLM 的 HTTP 错误处理:
  错误响应带响应体(截断 2000 字符)、空响应与无效 JSON 显式抛 InvalidDataException
- 空 catch 补全精确异常类型(IOException/UnauthorizedAccessException/JsonException)
- 修正 Program.cs 数据库初始化注释
- 新增 AI 客户端错误处理单元测试
This commit is contained in:
MingNian
2026-06-20 22:06:31 +08:00
parent 4d213b5a44
commit aa44d6f0f0
9 changed files with 182 additions and 256 deletions

View File

@@ -67,7 +67,8 @@ public sealed class DietImageAnalysisWorker(
foreach (var path in paths)
{
try { if (File.Exists(path)) File.Delete(path); }
catch { }
catch (IOException) { }
catch (UnauthorizedAccessException) { }
}
}
}

View File

@@ -521,7 +521,7 @@ public static class AiChatEndpoints
var json = JsonSerializer.Serialize(toolResult, JsonOpts);
resultDict = JsonSerializer.Deserialize<Dictionary<string, object>>(json, JsonOpts);
}
catch { resultDict = new Dictionary<string, object>(); }
catch (JsonException) { resultDict = new Dictionary<string, object>(); }
}
var isPendingConfirmation = resultDict != null

View File

@@ -202,7 +202,7 @@ app.UseStaticFiles(new StaticFileOptions
if (app.Environment.IsDevelopment())
app.MapOpenApi();
// ---- 初始化数据库(开发环境:每次重建)----
// ---- 初始化数据库:创建空库,并用版本化补丁更新已有本地结构 ----
using (var scope = app.Services.CreateScope())
{
var db = scope.ServiceProvider.GetRequiredService<AppDbContext>();