Yuvipanda has uploaded a new change for review.
https://gerrit.wikimedia.org/r/92478
Change subject: Wrap IOException when it happens with ApiException
......................................................................
Wrap IOException when it happens with ApiException
Change-Id: Ie47c8d6cb40a44d0e38ed264b9d14f282a95752a
---
M src/main/java/org/mediawiki/api/Api.java
M src/test/java/org/mediawiki/api/ApiTest.java
2 files changed, 24 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/apps/android/java-mwapi
refs/changes/78/92478/1
diff --git a/src/main/java/org/mediawiki/api/Api.java
b/src/main/java/org/mediawiki/api/Api.java
index 918de1f..4380e35 100644
--- a/src/main/java/org/mediawiki/api/Api.java
+++ b/src/main/java/org/mediawiki/api/Api.java
@@ -124,6 +124,8 @@
return new JSONObject(request.body());
} catch (JSONException e) {
throw new ApiException(e);
+ } catch (HttpRequest.HttpRequestException e) {
+ throw new ApiException(e.getCause());
}
}
}
diff --git a/src/test/java/org/mediawiki/api/ApiTest.java
b/src/test/java/org/mediawiki/api/ApiTest.java
index 057fbd2..f186c32 100644
--- a/src/test/java/org/mediawiki/api/ApiTest.java
+++ b/src/test/java/org/mediawiki/api/ApiTest.java
@@ -6,6 +6,8 @@
import org.json.JSONObject;
import org.junit.*;
+import java.io.IOException;
+
/**
* Tests that actually hit the API to return something.
*/
@@ -74,4 +76,24 @@
}
assertTrue("This means no exception was thrown, and hence test fails",
false);
}
+
+ /**
+ * Test for Network failure throwing the proper exception.
+ *
+ * Usually this happens due to various network failures, but since we can
not
+ * reproduce that reliably without network mocks, I am simply calling into
a
+ * random hopefully nonexistant hostname to get the network failure.
+ */
+ @Test
+ public void testNetworkException() {
+ Api api = new Api("blashblahblahdoesnotexist");
+ try {
+ api.action("somethingdoesnmtatter").param("format", "xml").get();
+ } catch (ApiException e) {
+ assertTrue(e.getCause() instanceof IOException);
+ return;
+ }
+ assertTrue("This means no exception was thrown, and hence test fails",
false);
+ }
+
}
--
To view, visit https://gerrit.wikimedia.org/r/92478
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie47c8d6cb40a44d0e38ed264b9d14f282a95752a
Gerrit-PatchSet: 1
Gerrit-Project: apps/android/java-mwapi
Gerrit-Branch: master
Gerrit-Owner: Yuvipanda <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits