Request for retrofit



  • I have a request.

     public void onResponse(Call<Count> call, Response<Count> response) {
    
                        Log.d("Response", String.valueOf(response.code()));
                        if (response.body().getmCount().equals("2")) {
                            Toast.makeText(getApplicationContext(), "У вас осталось: " + response.body().getmCount(), Toast.LENGTH_LONG);
                        } else if (response.body().getmCount().equals("1")) {
                            Toast.makeText(getApplicationContext(), "У вас осталось: " + response.body().getmCount(), Toast.LENGTH_LONG);
                        } else if (response.body().getmCount().equals("0")){
                            Toast.makeText(getApplicationContext(),"У вас осталось: "+response.body().getmCount(),Toast.LENGTH_LONG);
                            mCount = 0;
                        }
                    }
                    @Override
                    public void onFailure(Call&lt;Count&gt; call, Throwable t) {
    
                    }
                });
    

    But I have a mistake from server 401, in this mistake, I need to send a new request, how do I do it?



    1. Build a separate method, put a retrofit into the coys.
    2. In case of error or code 401, as you have, start this method.
    3. Call. return I don't want to do the code anymore.



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2