From e5e258035e6c43c8c68bfc0361fbd94eec507744 Mon Sep 17 00:00:00 2001 From: shangzhongyuan Date: Fri, 6 Mar 2026 11:16:32 +0800 Subject: [PATCH] =?UTF-8?q?fix(TradeOAService):=20=E5=A2=9E=E5=8A=A0OA?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E8=B0=83=E7=94=A8=E8=B6=85=E6=97=B6=E5=A4=84?= =?UTF-8?q?=E7=90=86=E5=92=8C=E5=BC=82=E5=B8=B8=E6=8D=95=E8=8E=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 增加60秒超时设置并捕获TaskCanceledException和其他异常,返回友好的错误信息 --- .../Modules/TradeModule/TradeOAService.cs | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/YLErpDAL/Modules/TradeModule/TradeOAService.cs b/YLErpDAL/Modules/TradeModule/TradeOAService.cs index 0d4a817b..41b31fab 100644 --- a/YLErpDAL/Modules/TradeModule/TradeOAService.cs +++ b/YLErpDAL/Modules/TradeModule/TradeOAService.cs @@ -296,14 +296,29 @@ namespace YLErp.Modules.TradeModule logger.Info($"国联OA接口URL: {requestUrl}"); // 调用OA接口 (POST请求,dataMap放在请求体中) - var httpClient = new HttpClientWrap(baseUrl); - var response = httpClient.PostJson(requestUrl, dataMap, null); + string response = null; + try + { + // 设置较长的超时时间,默认15秒可能不够 + var httpClient = new HttpClientWrap(baseUrl, 60); // 60秒超时 + response = httpClient.PostJson(requestUrl, dataMap, null); - logger.Info($"国联OA接口返回: {response}"); + logger.Info($"国联OA接口返回: {response}"); - // 解析响应 - var responseObj = JsonHelper.Deserialize(response); - return responseObj; + // 解析响应 + var responseObj = JsonHelper.Deserialize(response); + return responseObj; + } + catch (TaskCanceledException ex) + { + logger.Error($"调用OA接口时任务被取消:{ex.Message}", ex); + return new GuoLianOAResponse() { code = -2, data = new GuoLianOAData { msg = "调用OA接口超时,请检查网络连接" } }; + } + catch (Exception ex) + { + logger.Error($"调用OA接口时发生异常:{ex.Message},响应内容:{response}", ex); + return new GuoLianOAResponse() { code = -2, data = new GuoLianOAData { msg = $"调用OA接口时发生异常: {ex.Message}" } }; + } } catch (Exception ex) {