Skip to content

Commit

Permalink
部分调整
Browse files Browse the repository at this point in the history
  • Loading branch information
LJYcoder committed May 18, 2018
1 parent 706316c commit c4f0d77
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 28 deletions.
4 changes: 2 additions & 2 deletions devring/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
defaultConfig {
minSdkVersion 14
targetSdkVersion 23
versionCode 8
versionName "1.0.7"
versionCode 9
versionName "1.0.8"

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import com.google.gson.Gson;
import com.google.gson.JsonParseException;
import com.google.gson.reflect.TypeToken;

import org.json.JSONException;

Expand All @@ -28,39 +27,33 @@ public class ThrowableHandler {
public static HttpThrowable handleThrowable(Throwable throwable) {
if (throwable instanceof HttpException) {
return new HttpThrowable(HttpThrowable.HTTP_ERROR, "网络(协议)错误", throwable);
}
else if (throwable instanceof JsonParseException || throwable instanceof JSONException || throwable instanceof ParseException) {
} else if (throwable instanceof JsonParseException || throwable instanceof JSONException || throwable instanceof ParseException) {
return new HttpThrowable(HttpThrowable.PARSE_ERROR, "解析错误", throwable);
}
else if (throwable instanceof UnknownHostException) {
} else if (throwable instanceof UnknownHostException) {
return new HttpThrowable(HttpThrowable.NO_NET_ERROR, "DNS解析错误(无网络)", throwable);
}
else if (throwable instanceof SocketTimeoutException) {
} else if (throwable instanceof SocketTimeoutException) {
return new HttpThrowable(HttpThrowable.TIME_OUT_ERROR, "连接超时错误", throwable);
}
else if (throwable instanceof ConnectException) {
} else if (throwable instanceof ConnectException) {
return new HttpThrowable(HttpThrowable.CONNECT_ERROR, "连接错误", throwable);
}
else if (throwable instanceof javax.net.ssl.SSLHandshakeException) {
} else if (throwable instanceof javax.net.ssl.SSLHandshakeException) {
return new HttpThrowable(HttpThrowable.SSL_ERROR, "证书验证错误", throwable);
}
else {
return new HttpThrowable(HttpThrowable.UNKNOWN, "未知错误", throwable);
} else {
return new HttpThrowable(HttpThrowable.UNKNOWN, throwable.getMessage(), throwable);
}
}

/**
* 从HttpException类型的throwalbe中得到其响应实体并转换为指定格式
*
* @param throwable HttpException类型的throwalbe
* @param <T> 响应实体对应的格式
* @param clazz 响应实体对应的格式
*/
public static <T> T fromJson(Throwable throwable) {
public static <T> T fromJson(Throwable throwable, Class<T> clazz) {
HttpException httpException = (HttpException) throwable;
Gson gson = new Gson();
T t = null;
try {
t = gson.fromJson(httpException.response().errorBody().string(), new TypeToken<T>() {
}.getType());
t = gson.fromJson(httpException.response().errorBody().string(), clazz);
} catch (IOException e) {
e.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ public int getStackSize() {
*/
public void exitActivity(Activity activity) {
activity.finish();
mActivityStack.remove(activity);
}

/**
Expand Down Expand Up @@ -153,8 +152,7 @@ public void exitActivityLastIn(Class cls) {
continue;
}
if (activity.getClass().equals(cls)) {
activity.finish();
mActivityStack.removeElementAt(mActivityStack.lastIndexOf(activity));
exitActivity(activity);
break;
}
}
Expand Down Expand Up @@ -194,8 +192,4 @@ public void exitApplication() {
}
}





}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ KEY_ALIAS=dev_base_test
KEY_PASSWORD=123456
STORE_PASSWORD=123456

VERSION=1.0.7
VERSION=1.0.8
GROUP=com.ljy.ring

SITE_URL=https://github.com/LJYcoder/DevRing
Expand Down

0 comments on commit c4f0d77

Please sign in to comment.