Commit 152a71f0 by sikang

优化Http错误提示

parent 3889cf49
......@@ -49,26 +49,26 @@ public abstract class HttpObserver<T> implements Observer<T> {
String msg = throwable.getMessage();
try {
if (throwable != null) {
if (isHttpError(msg)) {
if (isNetworkError(msg)) {
onError(Error.HTTP_ERROR, LibConfig.getContext().getString(R.string.text_net_error));
} else if (throwable instanceof HttpException) {
HttpException exception = (HttpException) throwable;
if (!isCanHandle(exception)) {
String body = exception.response().errorBody().string();
ResponseErrorBody responseErrorBody = new Gson().fromJson(body, ResponseErrorBody.class);
onError(Error.SERVER_ERROR, responseErrorBody.getMessage());
onError(Error.SERVER_ERROR, "Server Exception: " + responseErrorBody.getMessage());
}
} else if (msg.contains("java.lang.IllegalStateException")) {
onError(Error.APP_ERROR, LibConfig.getContext().getString(R.string.text_app_error));
onError(Error.APP_ERROR, "Program Exception");
} else if (msg.contains("body is null")) {
onSuccess(null);
} else {
onError(Error.UNKNOW, msg);
onError(Error.UNKNOW, "Unknow Exception: " + msg);
}
}
} catch (Throwable e) {
onError(Error.APP_ERROR, msg);
onError(Error.APP_ERROR, "Program Exception: " + msg);
}
if (disposable != null)
disposable.dispose();
......@@ -99,7 +99,7 @@ public abstract class HttpObserver<T> implements Observer<T> {
BasicAck result = gson.fromJson(exception.response().body().toString(), BasicAck.class);
UpdateBean updateBean = gson.fromJson(result.getData(), UpdateBean.class);
EventBus.getDefault().post(updateBean);
}else{
} else {
EventBus.getDefault().post(new UpdateBean());
}
return true;
......@@ -118,7 +118,7 @@ public abstract class HttpObserver<T> implements Observer<T> {
/**
* 链路错误
*/
private boolean isHttpError(String msg) {
private boolean isNetworkError(String msg) {
String[] errorArray = new String[]{
"timeout",
"java.net.ConnectException",
......
......@@ -60,7 +60,7 @@ public class LoginManager {
PreferencesManager.get().clearLoginInfo();
tokenInfo = null;
//广播通知
LibConfig.getContext().sendBroadcast(new Intent(ActionEnum.LOGIN_INVALID.value()));
EventBus.getDefault().post(ActionEnum.LOGIN_INVALID);
if (LibConfig.isDefaultLoginMode()) {
//跳转登录界面
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment