deason 6 gadi atpakaļ
vecāks
revīzija
e765a6c732

+ 9 - 1
src/main/java/cn/com/qmth/examcloud/app/core/utils/HttpUtils.java

@@ -18,6 +18,8 @@ import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.slf4j.LoggerFactory;
 
 
+import java.net.ConnectException;
+
 import static cn.com.qmth.examcloud.app.model.Constants.*;
 import static cn.com.qmth.examcloud.app.model.Constants.*;
 
 
 /**
 /**
@@ -74,7 +76,13 @@ public class HttpUtils {
     }
     }
 
 
     public static Result<String> call(Request request) throws Exception {
     public static Result<String> call(Request request) throws Exception {
-        Response response = HttpClientBuilder.getClient().newCall(request).execute();
+        Response response;
+        try {
+            response = HttpClientBuilder.getClient().newCall(request).execute();
+        } catch (ConnectException e) {
+            log.error(e.getMessage());
+            return new Result<>().error("服务访问失败!");
+        }
         String bodyStr = response.body().string();
         String bodyStr = response.body().string();
         if (response.isSuccessful()) {
         if (response.isSuccessful()) {
             return new Result().success(bodyStr);
             return new Result().success(bodyStr);