fix: 修复空 catch 吞异常问题,端口号抽离到配置,统一日志为 Serilog
- 所有空 catch 块补全日志记录,统一使用 Serilog/AppLog - 按场景分级:Error(意外失败)、Warning(次要问题)、Information(预期内) - 端口 HttpPort/HttpsPort 抽离到 appsettings.json Server 配置节 - QrCodeService 通过 IConfiguration 读取端口,消除硬编码 - 前端通过 Vite proxy 转发 /api,http.ts 统一使用 origin 地址 - 移除所有 Debug.WriteLine 和 Serilog.Log.Debug 日志 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Avalonia.Controls;
|
||||
using FileShare_Common.Infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
@@ -180,6 +181,7 @@ namespace FileShare_PC.Views
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
AppLog.Error(ex, "Bridge AppRequest 处理失败");
|
||||
response = new AppResponse
|
||||
{
|
||||
Kind = "app-response",
|
||||
@@ -341,6 +343,7 @@ namespace FileShare_PC.Views
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
AppLog.Error(ex, "本地 HTTP 请求处理失败");
|
||||
response.StatusCode = 500;
|
||||
response.StatusMessage = "Internal Server Error";
|
||||
response.Body = JsonSerializer.Serialize(new { success = false, error = ex.Message });
|
||||
@@ -456,8 +459,9 @@ namespace FileShare_PC.Views
|
||||
using var document = JsonDocument.Parse(messageJson);
|
||||
return document.RootElement.TryGetProperty("id", out var idProperty) ? idProperty.GetString() : null;
|
||||
}
|
||||
catch
|
||||
catch (Exception ex)
|
||||
{
|
||||
AppLog.Information("解析 Bridge 请求 ID 失败: {Error}", ex.Message);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -537,8 +541,9 @@ namespace FileShare_PC.Views
|
||||
_ = Task.Run(() => HandleLocalHttpRequest(context, wwwRoot), cancellationToken);
|
||||
}
|
||||
}
|
||||
catch
|
||||
catch (Exception ex) when (ex is not OperationCanceledException)
|
||||
{
|
||||
AppLog.Error(ex, "本地 HTTP 服务循环异常退出");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -577,15 +582,17 @@ namespace FileShare_PC.Views
|
||||
await input.CopyToAsync(context.Response.OutputStream);
|
||||
context.Response.OutputStream.Close();
|
||||
}
|
||||
catch
|
||||
catch (Exception ex)
|
||||
{
|
||||
AppLog.Error(ex, "本地静态文件请求处理失败");
|
||||
try
|
||||
{
|
||||
context.Response.StatusCode = 500;
|
||||
context.Response.Close();
|
||||
}
|
||||
catch
|
||||
catch (Exception closeEx)
|
||||
{
|
||||
AppLog.Warning("关闭 500 响应失败: {Error}", closeEx.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -826,8 +833,9 @@ namespace FileShare_PC.Views
|
||||
_localHttpServer?.Stop();
|
||||
_localHttpServer?.Close();
|
||||
}
|
||||
catch
|
||||
catch (Exception ex)
|
||||
{
|
||||
AppLog.Warning("停止本地 HTTP 服务时出错: {Error}", ex.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user