Commit 216d5658 by sikang

update

parent 0fec2ba9
...@@ -56,7 +56,7 @@ public abstract class HttpObserver<T> implements Observer<T> { ...@@ -56,7 +56,7 @@ public abstract class HttpObserver<T> implements Observer<T> {
onFinish(); onFinish();
onSuccess(tResult); onSuccess(tResult);
} catch (Exception e) { } catch (Exception e) {
onError(Error.UNKNOW, action + " error"); onError(Error.UNKNOW, action + " - Result Exception : " + e.getMessage());
} }
} }
...@@ -64,29 +64,28 @@ public abstract class HttpObserver<T> implements Observer<T> { ...@@ -64,29 +64,28 @@ public abstract class HttpObserver<T> implements Observer<T> {
public void onError(Throwable throwable) { public void onError(Throwable throwable) {
onFinish(); onFinish();
String msg = throwable.getMessage(); String msg = throwable.getMessage();
LogUtils.d("HttpObserver", action + " -> error msg : " + msg);
try { try {
if (throwable != null) { if (throwable != null) {
if (isNetworkError(msg)) { if (isNetworkError(msg)) {
onError(Error.HTTP_ERROR, LibConfig.getContext().getString(R.string.text_net_error)); onError(Error.HTTP_ERROR, action + " - " + 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, action + " - ServerException" + responseErrorBody.getMessage());
} }
} else if (msg.contains("java.lang.IllegalStateException")) { } else if (msg.contains("java.lang.IllegalStateException")) {
onError(Error.APP_ERROR, "Program Exception"); onError(Error.APP_ERROR, action + " - 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, action + " " + msg); onError(Error.UNKNOW, action + " - ServerException" + msg);
} }
} }
} catch (Exception e) { } catch (Exception e) {
onError(Error.APP_ERROR, "Error: " + e.getMessage()); onError(Error.APP_ERROR, action + " - Unknown Exception" + e.getMessage());
} }
if (disposable != null) if (disposable != null)
disposable.dispose(); disposable.dispose();
......
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