Calling onFailure method in case the parsed response comes with a non-null error object
This commit is contained in:
parent
a8c13cac96
commit
bba825ca62
2 changed files with 8 additions and 3 deletions
|
@ -1,5 +1,7 @@
|
|||
package cy.agorise.graphenej.api;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import cy.agorise.graphenej.models.JsonRpcResponse;
|
||||
import okhttp3.Response;
|
||||
|
||||
|
@ -19,8 +21,8 @@ public interface ApiCallback {
|
|||
/**
|
||||
* Method called whenever there was an error and the response could not be delivered.
|
||||
*
|
||||
* @param t Error Trowable, potentially with some details about the problem.
|
||||
* @param t Error Throwable, potentially with some details about the problem.
|
||||
* @param response Node response, if any
|
||||
*/
|
||||
void onFailure(Throwable t, Response response);
|
||||
void onFailure(Throwable t, @Nullable Response response);
|
||||
}
|
||||
|
|
|
@ -565,7 +565,10 @@ public class NetworkService {
|
|||
// Executing callback, if present with the parsed response
|
||||
if(mCallbackMap.containsKey(response.id)){
|
||||
ApiCallback callback = mCallbackMap.get(response.id);
|
||||
callback.onResponse(parsedResponse, text);
|
||||
if(response.error == null)
|
||||
callback.onResponse(parsedResponse, text);
|
||||
else
|
||||
callback.onFailure(new Exception("Exception while trying to parse node response. Message: " + response.error.message), null);
|
||||
mCallbackMap.remove(response.id);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue