I want to handle error in Retrofit 2.0
Got e.g. code=404
and body=null
, but errorBody()
contains data in ErrorModel
(Boolean status
and String info
).
This is errorBody().content
: [text=\n{"status":false,"info":"Provided email doesn't exist."}]
.
How can I get this data?
Thank for helping me!
This is my code for Retrofit request:
ResetPasswordApi.Factory.getInstance().resetPassword(loginEditText.getText().toString())
.enqueue(new Callback<StatusInfoModel>() {
@Override
public void onResponse(Call<StatusInfoModel> call, Response<StatusInfoModel> response) {
if (response.isSuccessful()) {
showToast(getApplicationContext(), getString(R.string.new_password_sent));
} else {
showToast(getApplicationContext(), getString(R.string.email_not_exist));
}
}
@Override
public void onFailure(Call<StatusInfoModel> call, Throwable t) {
showToast(getApplicationContext(), "Something went wrong...");
}
});