fixed a major crash on time out in login screen.

This commit is contained in:
Kosh 2017-03-18 17:20:27 +08:00
parent 51ed7b9a2f
commit 490cc56dcd
3 changed files with 12 additions and 6 deletions

View File

@ -148,11 +148,13 @@ public class RestProvider {
}
@Nullable public static GitHubErrorResponse getErrorResponse(@NonNull Throwable throwable) {
RetrofitException error = (RetrofitException) throwable;
try {
return error.getErrorBodyAs(GitHubErrorResponse.class);
} catch (IOException e) {
e.printStackTrace();
if (throwable instanceof RetrofitException) {
RetrofitException error = (RetrofitException) throwable;
try {
return error.getErrorBodyAs(GitHubErrorResponse.class);
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}

View File

@ -3,6 +3,7 @@ package com.fastaccess.provider.rest.handler;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.net.SocketTimeoutException;
import retrofit2.Call;
import retrofit2.CallAdapter;
@ -53,6 +54,9 @@ public class RxErrorHandlingCallAdapterFactory extends CallAdapter.Factory {
}
private RetrofitException asRetrofitException(Throwable throwable) {
if (throwable instanceof SocketTimeoutException) {
return RetrofitException.unexpectedError(throwable);
}
if (throwable instanceof HttpException) {
HttpException httpException = (HttpException) throwable;
Response response = httpException.response();

View File

@ -39,7 +39,7 @@ class LoginPresenter extends BasePresenter<LoginMvp.View> implements LoginMvp.Pr
}
}
}
super.onError(throwable);
sendToView(view -> view.showErrorMessage(throwable.getMessage()));
}
@Override public void onTokenResponse(@Nullable AccessTokenModel modelResponse) {