This is my network request sample
networkAPI.postData(myData).enqueue(new Callback<MyResponse>() {
@Override
public void onResponse(Call<MyResponse> call, Response<MyResponse> response) {
if (response.code() == 201) {
// success
}
}
@Override
public void onFailure(Call<MyResponse> call, Throwable t) {
}
});
It is the request I should call only once as I've one time usable voucher code. If I turn off my network connection immediately or if it disconnects instantly after calling this method, then it moves to onFailure
method with IOException
in throwable which generally refers connection error, But the point is data posted to server and voucher code has been used and the problem is onFailure
method was called here.
I am sure that it is not a parsing failure hence I tried using Void
too. Why onResponse
is not called even after posting the data. How to overcome such situation?