Adarsh Yadav Adarsh Yadav - 5 months ago 61
Android Question

How to get Retrofit success responce status codes

I am not able to get success response status code from response like 200,201.. etc. As we can easily get error codes from

RetrofitError
class like
error.isNetworkError()
and
error.getResponse().getStatus()
. Is there any workaround for getting status codes?

jhm jhm
Answer

As per Retrofit 2.0.2, the call is now

@Override
public void onResponse(Call<YourModel> call, Response<YourModel> response) {
    if (response.code() == 200) {
       // Do awesome stuff
    } else {
       // Handle other response codes
    }
}

Hope it helps someone :-)