I am using HttpOK library with Java. I wrote the following code:
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
...
public class RunFeed implements Runnable {
private final OkHttpClient client = new OkHttpClient();
...
private Response executeRequest(Request request){
try {
final Call call = client.newCall(request);
Response response = call.execute();
if (!response.isSuccessful()) {
throw new IOException("Unexpected code " + response);
}
return response;
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}
The reason I wrote this kind of dirty code is to try and catch the exception which is being thrown on the call.execute(); line.
What happens is that when the program is reaching this line, the program exits (somehow successfully), without reaching the return response statement, or without any exceptions thrown and without entering the catch block or reaching the last, yes I know - "filthy" return null statement...
The client and request objects are not null and looks valid to me.
Another point to say is that I am running the code from within a runnable implemented class.
BTW, when the debugger reaches the call.execute(); line, and I evaluate the expression I get:
Response{protocol=http/1.1, code=200, message=OK, url=http://myurl}
So, it seems that everything is fine. But right after that, when I press the "step Over" button, it just finishes the execution instead of advancing to if (!response.isSuccessful())...
Please advise.