*/
package org.sonar.batch.repository;
-import org.sonar.api.utils.HttpDownloader.HttpException;
+import com.google.common.base.Throwables;
+import org.sonar.api.utils.HttpDownloader.HttpException;
import com.google.common.collect.HashBasedTable;
import com.google.common.collect.Table;
fromCache.setValue(result.isFromCache());
}
return processStream(result.get(), projectKey);
- } catch (IllegalStateException e) {
+ } catch (RuntimeException e) {
if (shouldThrow(e)) {
throw e;
}
}
private static boolean shouldThrow(Exception e) {
- if (e.getCause() != null && e.getCause() instanceof HttpException) {
- HttpException http = (HttpException) e.getCause();
- return http.getResponseCode() != 404;
+ for (Throwable t : Throwables.getCausalChain(e)) {
+ if (t instanceof HttpException) {
+ HttpException http = (HttpException) t;
+ return http.getResponseCode() != 404;
+ }
}
return false;
*/
package org.sonar.batch.repository;
+import org.sonar.api.utils.MessageException;
+
import com.google.common.io.Resources;
import java.io.ByteArrayInputStream;
when(wsLoader.loadStream(anyString())).thenThrow(e);
loader.load(PROJECT_KEY, false, null);
}
+
+ @Test
+ public void failFastHttpErrorMessageException() {
+ thrown.expect(MessageException.class);
+ thrown.expectMessage("http error");
+
+ HttpException http = new HttpException(URI.create("uri"), 403);
+ MessageException e = MessageException.of("http error", http);
+ when(wsLoader.loadStream(anyString())).thenThrow(e);
+ loader.load(PROJECT_KEY, false, null);
+ }
@Test
public void passIssuesModeParameter() {