From 87caff02993651dfe47b6231f89c8101cd2e32ae Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=B0=8F=E8=82=A5=E7=BE=8A?= <1048382248@qq.com>
Date: Tue, 11 Nov 2025 18:33:53 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20=E8=AF=B7=E6=B1=82=20?=
=?UTF-8?q?=E7=94=A8=E6=88=B7=E4=B8=AD=E5=BF=83API=E7=9A=84=E6=8D=95?=
=?UTF-8?q?=E8=8E=B7?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Learn.Archives.Core/Common/OhException.cs | 10 ++++++++++
Learn.Archives.Core/Common/UserCenterService.cs | 15 +++++++++++++--
Learn.Archives.Core/Learn.Archives.Core.csproj | 2 +-
3 files changed, 24 insertions(+), 3 deletions(-)
diff --git a/Learn.Archives.Core/Common/OhException.cs b/Learn.Archives.Core/Common/OhException.cs
index 72eca5c..fb36166 100644
--- a/Learn.Archives.Core/Common/OhException.cs
+++ b/Learn.Archives.Core/Common/OhException.cs
@@ -22,6 +22,16 @@ namespace Learn.Archives.Core.Common
throw new OhException(message, code);
}
///
+ /// 抛出 异常
+ ///
+ ///
+ ///
+ ///
+ public static T Error(string message, int code = 500)
+ {
+ throw new OhException(message, code);
+ }
+ ///
/// 抛出 模型校验异常
///
///
diff --git a/Learn.Archives.Core/Common/UserCenterService.cs b/Learn.Archives.Core/Common/UserCenterService.cs
index b4f32b1..530c17b 100644
--- a/Learn.Archives.Core/Common/UserCenterService.cs
+++ b/Learn.Archives.Core/Common/UserCenterService.cs
@@ -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>(resStr);
+ var resStr = string.Empty;
+ try
+ {
+ resStr= await responseMessage?.Content?.ReadAsStringAsync();
+
+ }
+ catch (Exception ex)
+ {
+ return Oh.Error($"请求用户中心出现异常 {resStr} {ex.Message}");
+ }
+ if(string.IsNullOrEmpty(resStr))
+ return Oh.Error($"请求用户中心出现异常 返回了空数据");
+ var res = JsonSerializer.Deserialize>(resStr);
if (res == null || res.Code != 200)
Oh.Error(res.Message, res.Code);
return res.Data;
diff --git a/Learn.Archives.Core/Learn.Archives.Core.csproj b/Learn.Archives.Core/Learn.Archives.Core.csproj
index d41fa79..91ba3a1 100644
--- a/Learn.Archives.Core/Learn.Archives.Core.csproj
+++ b/Learn.Archives.Core/Learn.Archives.Core.csproj
@@ -28,6 +28,6 @@
-
+