use of retrofit2.HttpException in project Varis-Android by dkhmelenko.
the class AuthPresenter method doLogin.
private void doLogin(Single<Authorization> authorizationJob) {
Disposable subscription = authorizationJob.flatMap(this::doAuthorization).doOnSuccess(this::saveAccessToken).doAfterSuccess(accessToken -> cleanUpAfterAuthorization()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe((authorization, throwable) -> {
getView().hideProgress();
if (throwable == null) {
getView().finishView();
} else {
HttpException httpException = (HttpException) throwable;
if (isTwoFactorAuthRequired(httpException)) {
mSecurityCodeInput = true;
getView().showTwoFactorAuth();
} else {
getView().showErrorMessage(throwable.getMessage());
}
}
});
mSubscriptions.add(subscription);
}
use of retrofit2.HttpException in project Varis-Android by dkhmelenko.
the class AuthPresenter method isTwoFactorAuthRequired.
private boolean isTwoFactorAuthRequired(HttpException exception) {
Response response = exception.response();
boolean twoFactorAuthRequired = false;
for (String header : response.headers().names()) {
if (GithubApiService.TWO_FACTOR_HEADER.equals(header)) {
twoFactorAuthRequired = true;
break;
}
}
return response.code() == HttpURLConnection.HTTP_UNAUTHORIZED && twoFactorAuthRequired;
}
Aggregations