mardi 25 août 2015

OkHttp callback eats up exceptions - design flaw or common practice

OkHttp library Callback interface is declared as

public interface Callback {
  void onFailure(Request request, IOException e);
  void onResponse(Response response) throws IOException;
}

Unhandled exceptions from onResponse method will get eaten up by Call class as I have recently discovered in Callback failure for cancelled call in OkHttp

I have few questions related to that design.


First, wouldn't it be better have different declaration of onResponse method in order to force catching exceptions in onResponse rather than throwing them, since they will be eaten up.

Is this design flaw in OkHttp Callback interface or is this kind of code common practice in Java?


Second, when http request reaches onResponse callback method I would expect that canceling request at that point should be prohibited. I would say this is a bug. Am I right?



from Newest questions tagged java - Stack Overflow http://ift.tt/1NSnzCe
via IFTTT

Aucun commentaire:

Enregistrer un commentaire