fix(TradeOAService): 增加OA接口调用超时处理和异常捕获
增加60秒超时设置并捕获TaskCanceledException和其他异常,返回友好的错误信息
This commit is contained in:
@@ -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<GuoLianOAResponse>(response);
|
||||
return responseObj;
|
||||
// 解析响应
|
||||
var responseObj = JsonHelper.Deserialize<GuoLianOAResponse>(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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user