I make a request (any, authorization, registration, etc.) and only then I find out that I need to update TOKEN , that is, I get an error 401 .
Here is a request for authorization:
BaseApplication.getApiClient() .signIn(accessToken, body) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new SingleObserver<UserProfile>() { @Override public void onSubscribe(Disposable d) { Log.d("-- SignInOnSubscribe", "Subscribed!"); } @Override public void onSuccess(UserProfile userProfile) { if (userProfile.getErrorDetails() != null) { onSignInFinishedCallback.onLoginFailure(userProfile.getErrorDetails()); Log.d("-- SignInOnError", userProfile.getErrorDetails()); } else { onSignInFinishedCallback.onLoginSuccess(userProfile); profileRepository.updateUserProfile(userProfile); Log.d("-- SignInOnSuccess", userProfile.getName()); } } @Override public void onError(Throwable e) { Log.d("-- SignInOnError", e.getMessage()); if (e.getMessage().equals(Constants.CODE_UNAUTHORIZED)){ // Действие при ошибке 401 } onSignInFinishedCallback.onLoginFailure(e.getMessage()); } }); API requests themselves:
@POST("/api/login") Single<UserProfile> getAccessToken(@Body Map<String, String> requestBody); @POST("/api/abonent/login") Single<UserProfile> signIn(@Header("X-ACCESS-TOKEN") String accessToken, @Body Map<String, String> requestBody); Let's say an authorization запрос 1 is запрос 1 , a TOKEN запрос 2 is запрос 2 .
Question: How to update TOKEN if I received an error in запросе 1 and after the success of запроса 2 , back to запрос 1 ?