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;