deason 6 лет назад
Родитель
Сommit
e765a6c732
1 измененных файлов с 9 добавлено и 1 удалено
  1. 9 1
      src/main/java/cn/com/qmth/examcloud/app/core/utils/HttpUtils.java

+ 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.LoggerFactory;
 
+import java.net.ConnectException;
+
 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 {
-        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();
         if (response.isSuccessful()) {
             return new Result().success(bodyStr);