deason 2 éve
szülő
commit
52764c3f54

+ 1 - 1
examcloud-starters/examcloud-face-verify-starter/src/main/java/cn/com/qmth/examcloud/starters/face/verify/common/CommonUtils.java

@@ -65,7 +65,7 @@ public class CommonUtils {
             log.error("imageUrl download error {} {}", imageUrl, e.getMessage(), e);
         }
 
-        throw new RuntimeException("图片加载失败!");
+        throw new IllegalArgumentException("图片加载失败!");
     }
 
     public static String urlEncode(String value) {

+ 14 - 13
examcloud-starters/examcloud-face-verify-starter/src/main/java/cn/com/qmth/examcloud/starters/face/verify/model/baidu/BaiduApiHelper.java

@@ -2,6 +2,7 @@ package cn.com.qmth.examcloud.starters.face.verify.model.baidu;
 
 import cn.com.qmth.examcloud.starters.face.verify.FaceVerifyProperties;
 import cn.com.qmth.examcloud.starters.face.verify.common.Constants;
+import cn.com.qmth.examcloud.starters.face.verify.common.FaceVerifyException;
 import cn.com.qmth.examcloud.starters.face.verify.common.HttpClientBuilder;
 import cn.com.qmth.examcloud.starters.face.verify.common.JsonHelper;
 import cn.com.qmth.examcloud.starters.face.verify.model.FaceResult;
@@ -19,11 +20,11 @@ public class BaiduApiHelper {
 
     public static BaiduSession getAccessToken(String apiKey, String apiSecret) {
         if (StringUtils.isBlank(apiKey)) {
-            throw new IllegalArgumentException("Baidu apiKey must be not empty.");
+            throw new IllegalArgumentException("[BAIDU] apiKey must be not empty.");
         }
 
         if (StringUtils.isBlank(apiSecret)) {
-            throw new IllegalArgumentException("Baidu apiSecret must be not empty.");
+            throw new IllegalArgumentException("[BAIDU] apiSecret must be not empty.");
         }
 
         String requestUrl = String.format("%s?grant_type=client_credentials&client_id=%s&client_secret=%s", Constants.BAIDU_TOKEN_URL, apiKey, apiSecret);
@@ -40,17 +41,17 @@ public class BaiduApiHelper {
                 }
             }
 
-            log.warn("[baidu] url:{} response:{} body:{}", requestUrl, response.code(), bodyStr);
-            throw new RuntimeException("获取 Baidu AccessToken 失败!");
+            log.warn("[BAIDU] url:{} response:{} body:{}", requestUrl, response.code(), bodyStr);
+            throw new FaceVerifyException("[BAIDU] 获取AccessToken失败!");
         } catch (IOException e) {
             log.error(e.getMessage(), e);
-            throw new RuntimeException("获取 Baidu AccessToken 异常!");
+            throw new FaceVerifyException("[BAIDU] 获取AccessToken异常!");
         }
     }
 
     public static FaceResult faceVerify(FaceVerifyProperties properties, String jsonParams) {
         if (StringUtils.isBlank(jsonParams)) {
-            throw new IllegalArgumentException("Baidu api params must be not empty.");
+            throw new IllegalArgumentException("[BAIDU] api params must be not empty.");
         }
 
         BaiduSession session = BaiduApiHelper.getAccessToken(properties.getBaiduKey(), properties.getBaiduSecret());
@@ -65,7 +66,7 @@ public class BaiduApiHelper {
 
     public static FaceResult faceVerifyUseLocalApi(FaceVerifyProperties properties, String jsonParams) {
         if (StringUtils.isBlank(jsonParams)) {
-            throw new IllegalArgumentException("Baidu api params must be not empty.");
+            throw new IllegalArgumentException("[BAIDU] api params must be not empty.");
         }
 
         String requestUrl = String.format("%s?appid=%s", properties.getBaiduLocalUrlPrefix() + Constants.BAIDU_FACE_VERIFY_LOCAL_URL, properties.getBaiduLocalAppId());
@@ -77,7 +78,7 @@ public class BaiduApiHelper {
 
     public static FaceResult faceDetect(FaceVerifyProperties properties, String jsonParams) {
         if (StringUtils.isBlank(jsonParams)) {
-            throw new IllegalArgumentException("Baidu api params must be not empty.");
+            throw new IllegalArgumentException("[BAIDU] api params must be not empty.");
         }
 
         BaiduSession session = BaiduApiHelper.getAccessToken(properties.getBaiduKey(), properties.getBaiduSecret());
@@ -92,7 +93,7 @@ public class BaiduApiHelper {
 
     public static FaceResult faceDetectUseLocalApi(FaceVerifyProperties properties, String jsonParams) {
         if (StringUtils.isBlank(jsonParams)) {
-            throw new IllegalArgumentException("Baidu api params must be not empty.");
+            throw new IllegalArgumentException("[BAIDU] api params must be not empty.");
         }
 
         String requestUrl = String.format("%s?appid=%s", properties.getBaiduLocalUrlPrefix() + Constants.BAIDU_FACE_DETECT_LOCAL_URL, properties.getBaiduLocalAppId());
@@ -104,7 +105,7 @@ public class BaiduApiHelper {
 
     public static FaceResult faceCompare(FaceVerifyProperties properties, String jsonParams, Double expectFaceCompareScore) {
         if (StringUtils.isBlank(jsonParams)) {
-            throw new IllegalArgumentException("Baidu api params must be not empty.");
+            throw new IllegalArgumentException("[BAIDU] api params must be not empty.");
         }
 
         BaiduSession session = BaiduApiHelper.getAccessToken(properties.getBaiduKey(), properties.getBaiduSecret());
@@ -119,7 +120,7 @@ public class BaiduApiHelper {
 
     public static FaceResult faceCompareUseLocalApi(FaceVerifyProperties properties, String jsonParams, Double expectFaceCompareScore) {
         if (StringUtils.isBlank(jsonParams)) {
-            throw new IllegalArgumentException("Baidu api params must be not empty.");
+            throw new IllegalArgumentException("[BAIDU] api params must be not empty.");
         }
 
         String requestUrl = String.format("%s?appid=%s", properties.getBaiduLocalUrlPrefix() + Constants.BAIDU_FACE_COMPARE_LOCAL_URL, properties.getBaiduLocalAppId());
@@ -226,12 +227,12 @@ public class BaiduApiHelper {
                 }
             }
 
-            log.warn("[baidu] url:{} response:{} cost:{}ms body:{}", requestUrl, response.code(), cost, bodyStr);
+            log.warn("[BAIDU] url:{} response:{} cost:{}ms body:{}", requestUrl, response.code(), cost, bodyStr);
         } catch (IOException e) {
             log.error(e.getMessage(), e);
         }
 
-        throw new RuntimeException("[baidu] 接口调用异常!");
+        throw new FaceVerifyException("[BAIDU] 人脸接口调用异常!");
     }
 
 }

+ 3 - 2
examcloud-starters/examcloud-face-verify-starter/src/main/java/cn/com/qmth/examcloud/starters/face/verify/model/faceplus/FacePlusApiHelper.java

@@ -2,6 +2,7 @@ package cn.com.qmth.examcloud.starters.face.verify.model.faceplus;
 
 import cn.com.qmth.examcloud.starters.face.verify.FaceVerifyProperties;
 import cn.com.qmth.examcloud.starters.face.verify.common.Constants;
+import cn.com.qmth.examcloud.starters.face.verify.common.FaceVerifyException;
 import cn.com.qmth.examcloud.starters.face.verify.common.HttpClientBuilder;
 import cn.com.qmth.examcloud.starters.face.verify.common.JsonHelper;
 import cn.com.qmth.examcloud.starters.face.verify.model.FaceResult;
@@ -118,12 +119,12 @@ public class FacePlusApiHelper {
                 }
             }
 
-            log.warn("[Face++] url:{} response:{} cost:{}ms body:{}", requestUrl, response.code(), cost, bodyStr);
+            log.warn("[FACE++] url:{} response:{} cost:{}ms body:{}", requestUrl, response.code(), cost, bodyStr);
         } catch (IOException e) {
             log.error(e.getMessage(), e);
         }
 
-        throw new RuntimeException("[Face++] 接口调用异常!");
+        throw new FaceVerifyException("[FACE++] 人脸接口调用异常!");
     }
 
 }