fix: 修复附件上传响应处理逻辑
修改UploadAttachmentResponse的code字段类型为string以匹配实际接口返回 添加异常处理逻辑,增强附件上传失败时的错误处理和信息记录
This commit is contained in:
@@ -48,7 +48,7 @@ namespace YLErp.Modules.TradeModule
|
||||
/// </summary>
|
||||
public class UploadAttachmentResponse
|
||||
{
|
||||
public int code { get; set; }
|
||||
public string code { get; set; }
|
||||
public List<UploadAttachmentData> data { get; set; }
|
||||
public string status { get; set; }
|
||||
}
|
||||
|
||||
@@ -147,18 +147,34 @@ namespace YLErp.Modules.TradeModule
|
||||
logger.Info($"附件上传接口返回: {responseContent}");
|
||||
|
||||
// 解析响应
|
||||
var uploadResponse = JsonHelper.Deserialize<UploadAttachmentResponse>(responseContent);
|
||||
if (uploadResponse.code == 0 && uploadResponse.data != null)
|
||||
try
|
||||
{
|
||||
// 提取annexId
|
||||
var annexIds = uploadResponse.data.Select(item => item.annexId).ToList();
|
||||
logger.Info($"成功上传附件,获取到{annexIds.Count}个附件ID");
|
||||
return annexIds;
|
||||
var uploadResponse = JsonHelper.Deserialize<UploadAttachmentResponse>(responseContent);
|
||||
if (uploadResponse != null)
|
||||
{
|
||||
if (uploadResponse.code == "0" && uploadResponse.data != null)
|
||||
{
|
||||
// 提取annexId
|
||||
var annexIds = uploadResponse.data.Select(item => item.annexId).ToList();
|
||||
logger.Info($"成功上传附件,获取到{annexIds.Count}个附件ID");
|
||||
return annexIds;
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.Error($"附件上传失败:{uploadResponse.status},code:{uploadResponse.code}");
|
||||
throw new Exception($"附件上传失败:{uploadResponse.status}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.Error("附件上传响应解析为空");
|
||||
throw new Exception("附件上传响应解析失败");
|
||||
}
|
||||
}
|
||||
else
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error($"附件上传失败:{uploadResponse.status}");
|
||||
throw new Exception($"附件上传失败:{uploadResponse.status}");
|
||||
logger.Error($"解析附件上传响应失败:{ex.Message},响应内容:{responseContent}", ex);
|
||||
throw new Exception($"解析附件上传响应失败:{ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user