public static String analyze(Throwable e) {
if (!NetConnectionUtils.isNetConnected(BaseApplication.getInstance())) {
return "当前网络不可用,请检查网络设置";
} else if (e instanceof UnknownHostException) {
return "网络错误,请重试";
} else if (e instanceof ConnectException) {
return "请求失败,请重试";
} else if (e instanceof MalformedJsonException) {
return "请求失败,请重试";
} else if (e instanceof SocketTimeoutException) {
return "请求超时,请重试";
} else {
return "请求失败,请重试";
}
}
java类android.util.MalformedJsonException的实例源码
ResponseExceptionJobber.java 文件源码
项目:RxJavaAndRetrofitSimple
阅读 31
收藏 0
点赞 0
评论 0
ZooniverseClientTest.java 文件源码
项目:android-galaxyzoo
阅读 21
收藏 0
点赞 0
评论 0
@Test
public void testLoginWithFailure() throws IOException {
final MockWebServer server = new MockWebServer();
//On failure, the server's response code is HTTP_OK,
//but it has a "success: false" parameter.
final MockResponse response = new MockResponse();
response.setResponseCode(HttpURLConnection.HTTP_OK);
response.setBody("test nonsense failure message");
server.enqueue(response);
server.start();
final ZooniverseClient client = createZooniverseClient(server);
try {
final LoginUtils.LoginResult result = client.loginSync("testusername", "testpassword");
assertNotNull(result);
assertFalse(result.getSuccess());
} catch (final ZooniverseClient.LoginException e) {
assertTrue(e.getCause() instanceof MalformedJsonException);
}
server.shutdown();
}
JsonSanitizer.java 文件源码
项目:365browser
阅读 24
收藏 0
点赞 0
评论 0
private static String sanitizeString(String string) throws MalformedJsonException {
if (!checkString(string)) {
throw new MalformedJsonException("Invalid escape sequence");
}
return string;
}