优化 请求 用户中心API的捕获

This commit is contained in:
小肥羊 2025-11-11 18:33:53 +08:00
parent ab4e9db779
commit 87caff0299
3 changed files with 24 additions and 3 deletions

View File

@ -22,6 +22,16 @@ namespace Learn.Archives.Core.Common
throw new OhException(message, code);
}
/// <summary>
/// 抛出 异常
/// </summary>
/// <param name="message"></param>
/// <param name="code"></param>
/// <exception cref="OhException"></exception>
public static T Error<T>(string message, int code = 500)
{
throw new OhException(message, code);
}
/// <summary>
/// 抛出 模型校验异常
/// </summary>
/// <param name="message"></param>

View File

@ -71,8 +71,19 @@ namespace Learn.Archives.Core.Common
requestMessage.Content = new StringContent(data.ToJson(), Encoding.UTF8, "application/json");
var responseMessage = await httpClient.SendAsync(requestMessage, HttpCompletionOption.ResponseHeadersRead);
var resStr = await responseMessage.Content?.ReadAsStringAsync();
var res = JsonSerializer.Deserialize<BaseReturn<UserImportRes>>(resStr);
var resStr = string.Empty;
try
{
resStr= await responseMessage?.Content?.ReadAsStringAsync();
}
catch (Exception ex)
{
return Oh.Error<UserImportRes>($"请求用户中心出现异常 {resStr} {ex.Message}");
}
if(string.IsNullOrEmpty(resStr))
return Oh.Error<UserImportRes>($"请求用户中心出现异常 返回了空数据");
var res = JsonSerializer.Deserialize<BaseReturn<UserImportRes>>(resStr);
if (res == null || res.Code != 200)
Oh.Error(res.Message, res.Code);
return res.Data;

View File

@ -28,6 +28,6 @@
<PackageReference Include="SqlSugar.IOC" Version="2.0.0" />
<PackageReference Include="SqlSugarCore" Version="5.1.4.170" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="UserCenter.Model" Version="1.4.4" />
<PackageReference Include="UserCenter.Model" Version="1.4.9" />
</ItemGroup>
</Project>