Search in sources :

Example 6 with HttpException

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);
}
Also used : CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) HttpURLConnection(java.net.HttpURLConnection) AccessToken(com.khmelenko.lab.varis.network.response.AccessToken) AppSettings(com.khmelenko.lab.varis.storage.AppSettings) Arrays(java.util.Arrays) HttpException(retrofit2.HttpException) TextUtils(android.text.TextUtils) Response(retrofit2.Response) MvpPresenter(com.khmelenko.lab.varis.mvp.MvpPresenter) GithubApiService(com.khmelenko.lab.varis.network.retrofit.github.GithubApiService) Single(io.reactivex.Single) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) EncryptionUtils(com.khmelenko.lab.varis.util.EncryptionUtils) Inject(javax.inject.Inject) List(java.util.List) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) TravisRestClient(com.khmelenko.lab.varis.network.retrofit.travis.TravisRestClient) StringUtils(com.khmelenko.lab.varis.util.StringUtils) AuthView(com.khmelenko.lab.varis.view.AuthView) AccessTokenRequest(com.khmelenko.lab.varis.network.request.AccessTokenRequest) AuthorizationRequest(com.khmelenko.lab.varis.network.request.AuthorizationRequest) Schedulers(io.reactivex.schedulers.Schedulers) Authorization(com.khmelenko.lab.varis.network.response.Authorization) GitHubRestClient(com.khmelenko.lab.varis.network.retrofit.github.GitHubRestClient) HttpException(retrofit2.HttpException)

Example 7 with HttpException

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;
}
Also used : Response(retrofit2.Response)

Aggregations

HttpException (retrofit2.HttpException)3 HttpException (retrofit2.adapter.rxjava.HttpException)3 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)2 Disposable (io.reactivex.disposables.Disposable)2 List (java.util.List)2 Test (org.junit.Test)2 Response (retrofit2.Response)2 TextUtils (android.text.TextUtils)1 TextView (android.widget.TextView)1 MvpPresenter (com.khmelenko.lab.varis.mvp.MvpPresenter)1 AccessTokenRequest (com.khmelenko.lab.varis.network.request.AccessTokenRequest)1 AuthorizationRequest (com.khmelenko.lab.varis.network.request.AuthorizationRequest)1 AccessToken (com.khmelenko.lab.varis.network.response.AccessToken)1 Authorization (com.khmelenko.lab.varis.network.response.Authorization)1 GitHubRestClient (com.khmelenko.lab.varis.network.retrofit.github.GitHubRestClient)1 GithubApiService (com.khmelenko.lab.varis.network.retrofit.github.GithubApiService)1 TravisRestClient (com.khmelenko.lab.varis.network.retrofit.travis.TravisRestClient)1 AppSettings (com.khmelenko.lab.varis.storage.AppSettings)1 EncryptionUtils (com.khmelenko.lab.varis.util.EncryptionUtils)1 StringUtils (com.khmelenko.lab.varis.util.StringUtils)1