From bba825ca6235cc10aa9d950877ed53f2bdae545b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nelson=20R=2E=20P=C3=A9rez?= Date: Tue, 3 Dec 2019 12:39:42 -0500 Subject: [PATCH] Calling onFailure method in case the parsed response comes with a non-null error object --- .../src/main/java/cy/agorise/graphenej/api/ApiCallback.java | 6 ++++-- .../cy/agorise/graphenej/api/android/NetworkService.java | 5 ++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/graphenej/src/main/java/cy/agorise/graphenej/api/ApiCallback.java b/graphenej/src/main/java/cy/agorise/graphenej/api/ApiCallback.java index dc04acf..188711a 100644 --- a/graphenej/src/main/java/cy/agorise/graphenej/api/ApiCallback.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/api/ApiCallback.java @@ -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); } diff --git a/graphenej/src/main/java/cy/agorise/graphenej/api/android/NetworkService.java b/graphenej/src/main/java/cy/agorise/graphenej/api/android/NetworkService.java index 19172c9..6fcc810 100644 --- a/graphenej/src/main/java/cy/agorise/graphenej/api/android/NetworkService.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/api/android/NetworkService.java @@ -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); }