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) {