Commit 152a71f0 by sikang

优化Http错误提示

parent 3889cf49
...@@ -49,26 +49,26 @@ public abstract class HttpObserver<T> implements Observer<T> { ...@@ -49,26 +49,26 @@ public abstract class HttpObserver<T> implements Observer<T> {
String msg = throwable.getMessage(); String msg = throwable.getMessage();
try { try {
if (throwable != null) { if (throwable != null) {
if (isHttpError(msg)) { if (isNetworkError(msg)) {
onError(Error.HTTP_ERROR, LibConfig.getContext().getString(R.string.text_net_error)); onError(Error.HTTP_ERROR, LibConfig.getContext().getString(R.string.text_net_error));
} else if (throwable instanceof HttpException) { } else if (throwable instanceof HttpException) {
HttpException exception = (HttpException) throwable; HttpException exception = (HttpException) throwable;
if (!isCanHandle(exception)) { if (!isCanHandle(exception)) {
String body = exception.response().errorBody().string(); String body = exception.response().errorBody().string();
ResponseErrorBody responseErrorBody = new Gson().fromJson(body, ResponseErrorBody.class); 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")) { } 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")) { } else if (msg.contains("body is null")) {
onSuccess(null); onSuccess(null);
} else { } else {
onError(Error.UNKNOW, msg); onError(Error.UNKNOW, "Unknow Exception: " + msg);
} }
} }
} catch (Throwable e) { } catch (Throwable e) {
onError(Error.APP_ERROR, msg); onError(Error.APP_ERROR, "Program Exception: " + msg);
} }
if (disposable != null) if (disposable != null)
disposable.dispose(); disposable.dispose();
...@@ -99,7 +99,7 @@ public abstract class HttpObserver<T> implements Observer<T> { ...@@ -99,7 +99,7 @@ public abstract class HttpObserver<T> implements Observer<T> {
BasicAck result = gson.fromJson(exception.response().body().toString(), BasicAck.class); BasicAck result = gson.fromJson(exception.response().body().toString(), BasicAck.class);
UpdateBean updateBean = gson.fromJson(result.getData(), UpdateBean.class); UpdateBean updateBean = gson.fromJson(result.getData(), UpdateBean.class);
EventBus.getDefault().post(updateBean); EventBus.getDefault().post(updateBean);
}else{ } else {
EventBus.getDefault().post(new UpdateBean()); EventBus.getDefault().post(new UpdateBean());
} }
return true; return true;
...@@ -118,7 +118,7 @@ public abstract class HttpObserver<T> implements Observer<T> { ...@@ -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[]{ String[] errorArray = new String[]{
"timeout", "timeout",
"java.net.ConnectException", "java.net.ConnectException",
......
...@@ -60,7 +60,7 @@ public class LoginManager { ...@@ -60,7 +60,7 @@ public class LoginManager {
PreferencesManager.get().clearLoginInfo(); PreferencesManager.get().clearLoginInfo();
tokenInfo = null; tokenInfo = null;
//广播通知 //广播通知
LibConfig.getContext().sendBroadcast(new Intent(ActionEnum.LOGIN_INVALID.value())); EventBus.getDefault().post(ActionEnum.LOGIN_INVALID);
if (LibConfig.isDefaultLoginMode()) { 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