From f400960548cb266f92b68ec20d0e1bba4882c01c Mon Sep 17 00:00:00 2001 From: Thodoris1999 Date: Tue, 11 Sep 2018 21:18:22 +0300 Subject: [PATCH] merge createRequest and getResponse --- .../gr/thmmy/mthmmy/utils/parsing/NetworkTask.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/NetworkTask.java b/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/NetworkTask.java index a137ebdb..a63f954e 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/NetworkTask.java +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/NetworkTask.java @@ -30,11 +30,13 @@ public abstract class NetworkTask extends ExternalAsyncTask @Override protected final Parcel doInBackground(String... input) { - Request request = createRequest(input); - Response response = getResponse(request, BaseApplication.getInstance().getClient()); + Response response = sendRequest(BaseApplication.getInstance().getClient(), input); String responseBodyString; try { responseBodyString = response.body().string(); + } catch (NullPointerException npe) { + Timber.e(npe, "Invalid response. Detatails: https://square.github.io/okhttp/3.x/okhttp/okhttp3/Response.html#body--"); + return new Parcel<>(Parcel.ResultCode.NETWORK_ERROR, null); } catch (IOException e) { Timber.e(e); return new Parcel<>(Parcel.ResultCode.NETWORK_ERROR, null); @@ -60,9 +62,7 @@ public abstract class NetworkTask extends ExternalAsyncTask super.onPostExecute(tParcel); } - protected abstract Request createRequest(String... input); - - protected abstract Response getResponse(Request request, OkHttpClient client); + protected abstract Response sendRequest(OkHttpClient client, String... input); protected abstract T performTask(Document document) throws ParseException;