Browse Source

转发接口失败异常处理

xueyiming 3 tháng trước cách đây
mục cha
commit
7e36126f22

+ 25 - 13
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/video/impl/MatchVideoServiceImpl.java

@@ -168,12 +168,18 @@ public class MatchVideoServiceImpl implements MatchVideoService {
         String traceId = getOffVideosParam.getTraceId();
         LongArticlesMatchVideo matchVideo = longArticlesMatchVideoRepository.getByTraceId(traceId);
         if (matchVideo == null) {
-            String url = "http://192.168.205.85:8111/get_off_videos";
-            JSONObject param = new JSONObject();
-            param.put("traceId", getOffVideosParam.getTraceId());
-            HttpResponseContent httpResponseContent = HttpClientUtils.postData(url, param.toJSONString(),
-                    HttpClientUtils.contentTypeJson);
-            return JSONObject.parseObject(httpResponseContent.getBodyContent());
+            try {
+                String url = "http://192.168.205.85:8111/get_off_videos";
+                JSONObject param = new JSONObject();
+                param.put("traceId", getOffVideosParam.getTraceId());
+                HttpResponseContent httpResponseContent = HttpClientUtils.postData(url, param.toJSONString(),
+                        HttpClientUtils.contentTypeJson);
+                return JSONObject.parseObject(httpResponseContent.getBodyContent());
+            } catch (Exception e) {
+                log.error("old get_off_videos error", e);
+            }
+            res.put("error", "old get_off_videos error");
+            return res;
         }
         String ghId = matchVideo.getGhId();
         String response = matchVideo.getResponse();
@@ -209,13 +215,19 @@ public class MatchVideoServiceImpl implements MatchVideoService {
         Integer miniprogramUseType = recallVideosParam.getMiniprogramUseType();
         LongArticlesMatchVideo matchVideo = longArticlesMatchVideoRepository.getByTraceId(traceId);
         if (matchVideo == null) {
-            String url = "http://192.168.205.85:8111/recall_videos";
-            JSONObject param = new JSONObject();
-            param.put("traceId", traceId);
-            param.put("miniprogramUseType", miniprogramUseType);
-            HttpResponseContent httpResponseContent = HttpClientUtils.postData(url, param.toJSONString(),
-                    HttpClientUtils.contentTypeJson);
-            return JSONObject.parseObject(httpResponseContent.getBodyContent());
+            try {
+                String url = "http://192.168.205.85:8111/recall_videos";
+                JSONObject param = new JSONObject();
+                param.put("traceId", traceId);
+                param.put("miniprogramUseType", miniprogramUseType);
+                HttpResponseContent httpResponseContent = HttpClientUtils.postData(url, param.toJSONString(),
+                        HttpClientUtils.contentTypeJson);
+                return JSONObject.parseObject(httpResponseContent.getBodyContent());
+            } catch (Exception e) {
+                log.error("old recall_videos error", e);
+            }
+            res.put("error", "old recall_videos error");
+            return res;
         }
         LongArticlesMatchVideo longArticlesMatchVideo = longArticlesMatchVideoRepository.getByTraceId(traceId);
         if (Objects.equals(longArticlesMatchVideo.getContentStatus(), ConstantStatusEnum.TASK_PUBLISHED_CODE.getCode())) {