Reputation: 75
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
Reputation: 215
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.
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