]> source.dussan.org Git - sonarqube.git/commitdiff
Return content when exception is generated in ws client
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 8 Sep 2016 08:32:45 +0000 (10:32 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 8 Sep 2016 09:54:30 +0000 (11:54 +0200)
sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/DefaultProjectRepositoriesLoaderTest.java
sonar-ws/src/main/java/org/sonarqube/ws/client/BaseResponse.java
sonar-ws/src/main/java/org/sonarqube/ws/client/HttpException.java
sonar-ws/src/test/java/org/sonarqube/ws/client/BaseServiceTest.java
sonar-ws/src/test/java/org/sonarqube/ws/client/HttpExceptionTest.java

index b66e883ebe1e9f0c3367ecfef265bcdbb56a685a..3259d288083a148f3b84d90071f61b2b25d4409a 100644 (file)
@@ -31,9 +31,6 @@ import org.junit.rules.ExpectedException;
 import org.sonar.api.utils.MessageException;
 import org.sonar.scanner.WsTestUtil;
 import org.sonar.scanner.bootstrap.BatchWsClient;
-import org.sonar.scanner.repository.DefaultProjectRepositoriesLoader;
-import org.sonar.scanner.repository.FileData;
-import org.sonar.scanner.repository.ProjectRepositories;
 import org.sonarqube.ws.WsBatch.WsProjectResponse;
 import org.sonarqube.ws.client.HttpException;
 import org.sonarqube.ws.client.WsRequest;
@@ -76,7 +73,7 @@ public class DefaultProjectRepositoriesLoaderTest {
 
   @Test(expected = IllegalStateException.class)
   public void failFastHttpError() {
-    HttpException http = new HttpException("url", 403);
+    HttpException http = new HttpException("url", 403, null);
     IllegalStateException e = new IllegalStateException("http error", http);
     WsTestUtil.mockException(wsClient, e);
     loader.load(PROJECT_KEY, false);
@@ -87,7 +84,7 @@ public class DefaultProjectRepositoriesLoaderTest {
     thrown.expect(MessageException.class);
     thrown.expectMessage("http error");
 
-    HttpException http = new HttpException("uri", 403);
+    HttpException http = new HttpException("uri", 403, null);
     MessageException e = MessageException.of("http error", http);
     WsTestUtil.mockException(wsClient, e);
     loader.load(PROJECT_KEY, false);
index f97a919ec9155a0aff56b4734b683f160fc810f6..6949f4fe9a670507f5c296838a1b4243246367f3 100644 (file)
@@ -31,8 +31,9 @@ abstract class BaseResponse implements WsResponse {
   @Override
   public WsResponse failIfNotSuccessful() {
     if (!isSuccessful()) {
+      String content = content();
       close();
-      throw new HttpException(requestUrl(), code());
+      throw new HttpException(requestUrl(), code(), content);
     }
     return this;
   }
index b69cd4826799daaa299e685d00521a76abdbcba1..462145d6a45425366dd2728d664d222f9121e0be 100644 (file)
@@ -27,8 +27,8 @@ public class HttpException extends RuntimeException {
   private final String url;
   private final int code;
 
-  public HttpException(String url, int code) {
-    super(String.format("Error %d on %s", code, url));
+  public HttpException(String url, int code, String content) {
+    super(String.format("Error %d on %s : %s", code, url, content));
     this.url = url;
     this.code = code;
   }
index e7e0a43dc2d087833d7ef2b97278b070ca19471a..5b1b8d411ae010e0969e2327d64775f9395410eb 100644 (file)
@@ -74,7 +74,7 @@ public class BaseServiceTest {
 
       public void test() {
         GetRequest get = new GetRequest(path("issue")).setParam("key", "ABC");
-        when(wsConnector.call(get)).thenReturn(new MockWsResponse().setCode(403).setRequestUrl("https://local/foo"));
+        when(wsConnector.call(get)).thenReturn(new MockWsResponse().setCode(403).setRequestUrl("https://local/foo").setContent("error"));
 
         try {
           call(get, Testing.Fake.parser());
index 17ed590f744399804080499c7fe04cf63c499a99..c379a4f88517a29ac20f2a5fedd8613e0473145b 100644 (file)
@@ -26,9 +26,9 @@ import static org.assertj.core.api.Assertions.assertThat;
 public class HttpExceptionTest {
   @Test
   public void test_exception() throws Exception {
-    HttpException exception = new HttpException("http://localhost:9000/api/search", 500);
+    HttpException exception = new HttpException("http://localhost:9000/api/search", 500, "error");
     assertThat(exception.code()).isEqualTo(500);
     assertThat(exception.url()).isEqualTo("http://localhost:9000/api/search");
-    assertThat(exception.getMessage()).isEqualTo("Error 500 on http://localhost:9000/api/search");
+    assertThat(exception.getMessage()).isEqualTo("Error 500 on http://localhost:9000/api/search : error");
   }
 }