Переглянути джерело

跨服务调用异常处理

dengsixing 3 роки тому
батько
коміт
3f6d1e8366

+ 13 - 0
4dkankan-center-scene/src/main/java/com/fdkankan/scene/callback/FdkkMiniReqErrorCallback.java

@@ -1,5 +1,7 @@
 package com.fdkankan.scene.callback;
 
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
 import com.dtflys.forest.callback.OnError;
 import com.dtflys.forest.callback.OnSuccess;
 import com.dtflys.forest.exceptions.ForestRuntimeException;
@@ -7,6 +9,7 @@ import com.dtflys.forest.http.ForestRequest;
 import com.dtflys.forest.http.ForestResponse;
 import com.fdkankan.common.constant.ServerCode;
 import com.fdkankan.common.exception.BusinessException;
+import com.fdkankan.common.response.Result;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Component;
 
@@ -24,6 +27,16 @@ public class FdkkMiniReqErrorCallback implements OnError {
     @Override
     public void onError(ForestRuntimeException e, ForestRequest forestRequest,
         ForestResponse forestResponse) {
+        JSONObject jsonObject = JSON.parseObject(forestResponse.getContent());
+        Integer status = jsonObject.getInteger("status");
+        if(status != null && status == 500){
+            log.error("v3接口报错,status:{},error:{}", status, jsonObject.getString("error"));
+            throw new BusinessException(ServerCode.SYSTEM_ERROR);
+        }
+        Result result = JSON.parseObject(forestResponse.getContent(), Result.class);
+        if(result.getCode() != ServerCode.SUCCESS.code()){
+            throw new BusinessException(result.getCode(), result.getMsg());
+        }
         log.error("跨服务请求失败!", e);
         throw new BusinessException(ServerCode.FEIGN_REQUEST_FAILD);
     }

+ 1 - 0
4dkankan-center-scene/src/main/java/com/fdkankan/scene/httpclient/FdkankanMiniClient.java

@@ -13,6 +13,7 @@ import com.dtflys.forest.http.ForestResponse;
 import com.fdkankan.common.response.Result;
 import com.fdkankan.scene.bean.CameraBean;
 import com.fdkankan.scene.bean.UserIncrementBean;
+//import com.fdkankan.scene.callback.FdkkMiniReqSuccessCondition;
 import com.fdkankan.scene.callback.FdkkMiniReqSuccessCondition;
 import com.fdkankan.scene.entity.SceneProV3;
 import java.io.File;