httpClient: if my request fails, how should I restart it?

0

Good morning.

When I make a request and it fails for a specific error, I must refresh the token I sent in the header of the original request, and then resend the initial request with the new token. How could I do this generic for all my services?

I tried this:

new PostReviewAsyncTask(new PostReviewAsyncResponse() {
        @Override
        public void onReceive(boolean p) {


            if(p){
                DetailFragment.update(Id,DetailFragment.getContext());
                finish();
                Toast.makeText(UserReviewActivity.this, "Review exitoso", Toast.LENGTH_LONG).show();

            }else{
                Toast.makeText(UserReviewActivity.this, "Problema con review", Toast.LENGTH_LONG).show();
            }
        }
    }).execute(nuevoToken);

    //si retorna 401 refrescamos token y lanzamos la peticion de nuevo
    if(!post){
        new RefreshTokenAsyncTask(new RefreshTokenAsyncResponse(){
            @Override
            public void onReceive(String token) {
               nuevoToken = token;
            }
        }).execute(refreshToken);

        new PostReviewAsyncTask(new PostReviewAsyncResponse() {
            @Override
            public void onReceive(boolean p) {

            }
        }).execute(nuevoToken);
    }

But I would have to do the same in each service, so it would not be right from my point of view.

    
asked by devjav 29.11.2016 в 16:16
source

0 answers