Quellcode durchsuchen

捕获附件上传异常

tangjiang vor 10 Monaten
Ursprung
Commit
f8a3079119
1 geänderte Dateien mit 45 neuen und 43 gelöschten Zeilen
  1. 45 43
      src/DataSharing/Province/SendTask/TaskProvinceOtherJob.cs

+ 45 - 43
src/DataSharing/Province/SendTask/TaskProvinceOtherJob.cs

@@ -490,10 +490,17 @@ namespace DataSharing.Province.SendTask
                             }
                             else if (sendTask.PathType == EPathType.File)  //附件
                             {
-                                if (sendTask != null && sendTask.FileJson != null && sendTask.FileJson.Count > 0)
+                                try
+                                {
+                                    if (sendTask != null && sendTask.FileJson != null && sendTask.FileJson.Count > 0)
+                                    {
+                                        var itemFile = sendTask.FileJson[0];
+                                        result = await SendFileData(sendTask.Request, itemFile.FileId, itemFile.FileId, context.CancellationToken);
+                                    }
+                                }
+                                catch (Exception ex)
                                 {
-                                    var itemFile = sendTask.FileJson[0];
-                                    result = await SendFileData(sendTask.Request, itemFile.FileId, itemFile.FileId, context.CancellationToken);
+                                    error = ex.Message;
                                 }
                             }
                             _logger.LogWarning("省接口返回:" + name + "--------------" + System.Text.RegularExpressions.Regex.Unescape(System.Text.Json.JsonSerializer.Serialize(result)));
@@ -593,59 +600,54 @@ namespace DataSharing.Province.SendTask
             var configProvince = _channelConfigurationManager.GetConfigurationProvince();
             var businessFile = _channelConfigurationManager.GetConfigurationBusinessFile();
             byte[] fileContentBytes = null;
-            try
+
+            var baseAddress = businessFile.BaseUrl;
+            if (!baseAddress.EndsWith('/'))
+                baseAddress += "/";
+            string url = string.Format("{0}{1}?Source={2}&Id={3}", baseAddress, businessFile.DownloadUrlAddress, "hotline", fileId);
+            using (var client = _httpClientFactory.CreateClient())
+            using (var response = await client.GetAsync(url))
             {
-                var baseAddress = businessFile.BaseUrl;
-                if (!baseAddress.EndsWith('/'))
-                    baseAddress += "/";
-                string url = string.Format("{0}{1}?Source={2}&Id={3}", baseAddress, businessFile.DownloadUrlAddress, "hotline", fileId);
-                using (var client = _httpClientFactory.CreateClient())
-                using (var response = await client.GetAsync(url))
-                {
 
-                    if (response.StatusCode == HttpStatusCode.OK)
-                    {
-                        fileName = response.Content.Headers.ContentDisposition.FileNameStar;
-                        using var memoryStream = new MemoryStream();
-                        await response.Content.CopyToAsync(memoryStream);
-                        memoryStream.Seek(0, SeekOrigin.Begin);
+                if (response.StatusCode == HttpStatusCode.OK)
+                {
+                    fileName = response.Content.Headers.ContentDisposition.FileNameStar;
+                    using var memoryStream = new MemoryStream();
+                    await response.Content.CopyToAsync(memoryStream);
+                    memoryStream.Seek(0, SeekOrigin.Begin);
 
-                        fileContentBytes = memoryStream.ToArray();
-                    }
+                    fileContentBytes = memoryStream.ToArray();
                 }
-                if (fileContentBytes != null)
-                {
-                    //获取附件上传Token
-                    string strToken = await _xieTongClient.GetTokenAsync(cancellationToken);
-                    Dictionary<string, object> dicParam = new()
+            }
+            if (fileContentBytes != null)
+            {
+                //获取附件上传Token
+                string strToken = await _xieTongClient.GetTokenAsync(cancellationToken);
+                Dictionary<string, object> dicParam = new()
                     {
                         { "params",  request } // 第一个接口参数,json格式字符串
                     };
 
-                    // 构造字典文件数据
-                    // 接口参数名称为files
-                    CFormUpload.FileParameter fileParameter = new CFormUpload.FileParameter("files", fileContentBytes, fileName, null);
-                    dicParam.Add(fileName, fileParameter);
+                // 构造字典文件数据
+                // 接口参数名称为files
+                CFormUpload.FileParameter fileParameter = new CFormUpload.FileParameter("files", fileContentBytes, fileName, null);
+                dicParam.Add(fileName, fileParameter);
 
-                    var baseAddressHuiJu = configProvince.HuiJu;
-                    if (!baseAddressHuiJu.EndsWith('/'))
-                        baseAddressHuiJu += "/";
+                var baseAddressHuiJu = configProvince.HuiJu;
+                if (!baseAddressHuiJu.EndsWith('/'))
+                    baseAddressHuiJu += "/";
 
-                    string strUrl = baseAddressHuiJu + "get_case_material_info";
-                    // 上传附件
-                    string strResult = CFormUpload.MultipartFormDataPost(strUrl, null, dicParam, strToken);
+                string strUrl = baseAddressHuiJu + "get_case_material_info";
+                // 上传附件
+                string strResult = CFormUpload.MultipartFormDataPost(strUrl, null, dicParam, strToken);
 
-                    _logger.LogWarning("省接口上传附件返回:--------------" + strResult);
+                _logger.LogWarning("省接口上传附件返回:--------------" + strResult);
 
-                    if (!string.IsNullOrEmpty(strResult))
-                        return JsonConvert.DeserializeObject<ProvinceResponse>(strResult);
-                }
-                return new ProvinceResponse();
-            }
-            catch (Exception ex)
-            {
-                return new ProvinceResponse();
+                if (!string.IsNullOrEmpty(strResult))
+                    return JsonConvert.DeserializeObject<ProvinceResponse>(strResult);
             }
+            return new ProvinceResponse();
+
         }
 
         /// <summary>