javad ff
javad ff

Reputation: 75

Difference between retrofit callbacks

I want to know what is the difference between onFailure and when response is not successful in retrofit

call.enqueue(new Callback<Void>() {
    @Override
    public void onResponse(Call<Void> call, Response<Void> response) {

        if (!response.isSuccessful()){
            *1
        }
    }

    @Override
    public void onFailure(Call<Void> call, Throwable t) {
        *2
    }
});

When will be on *1 and *2 in the above callback

Upvotes: 3

Views: 1122

Answers (1)

Mohsin Khan
Mohsin Khan

Reputation: 215

  • onResponse

void onResponse(Call call, Response response) Invoked for a received HTTP response. Note: An HTTP response may still indicate an application-level failure such as a 404 or 500. Call Response.isSuccessful() to determine if the response indicates success.

  • onFailure

void onFailure(Call call, Throwable t) Invoked when a network exception occurred talking to the server or when an unexpected exception occurred creating the request or processing the response.

Upvotes: 6

Related Questions