]> source.dussan.org Git - sonar-scanner-cli.git/commitdiff
Improve quality
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Thu, 13 Aug 2015 15:19:32 +0000 (17:19 +0200)
committerDuarte Meneses <duarte.meneses@sonarsource.com>
Thu, 13 Aug 2015 15:19:32 +0000 (17:19 +0200)
sonar-runner-api/src/main/java/org/sonar/runner/impl/ServerConnection.java

index eb1002f6277b3aab3dda8bd51bc68c2d4b9e0a56..5b306bd3611b602e8c527500064716979564672e 100644 (file)
@@ -143,11 +143,8 @@ class ServerConnection {
     try {
       return downloadString(fullUrl, isCacheEnable);
     } catch (HttpRequest.HttpRequestException e) {
-      if (e.getCause() instanceof ConnectException || e.getCause() instanceof UnknownHostException ||
-        e.getCause() instanceof java.net.SocketTimeoutException) {
-        if (isCacheEnable) {
-          return fallbackToCache(fullUrl, e);
-        }
+      if (isCausedByConnection(e) && isCacheEnable) {
+        return fallbackToCache(fullUrl, e);
       }
 
       logger.error(MessageFormat.format(SONAR_SERVER_CAN_NOT_BE_REACHED, serverUrl));
@@ -155,6 +152,11 @@ class ServerConnection {
     }
   }
 
+  private boolean isCausedByConnection(Exception e) {
+    return e.getCause() instanceof ConnectException || e.getCause() instanceof UnknownHostException ||
+      e.getCause() instanceof java.net.SocketTimeoutException;
+  }
+
   private String fallbackToCache(String fullUrl, HttpRequest.HttpRequestException originalException) {
     logger.info(MessageFormat.format(SONAR_SERVER_CAN_NOT_BE_REACHED + ", trying cache", serverUrl));