From 4f67fd8e9495215c49bd4810d36b8a8723358e80 Mon Sep 17 00:00:00 2001 From: Anthony Restaino Date: Sat, 21 Nov 2015 17:44:45 -0500 Subject: [PATCH] Catch non 2xx responses and don't try to open an input stream --- .../java/acr/browser/lightning/object/SearchAdapter.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/src/main/java/acr/browser/lightning/object/SearchAdapter.java b/app/src/main/java/acr/browser/lightning/object/SearchAdapter.java index b186682..3ab50a2 100644 --- a/app/src/main/java/acr/browser/lightning/object/SearchAdapter.java +++ b/app/src/main/java/acr/browser/lightning/object/SearchAdapter.java @@ -6,6 +6,7 @@ import android.graphics.drawable.Drawable; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.os.AsyncTask; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -49,6 +50,7 @@ import acr.browser.lightning.utils.Utils; public class SearchAdapter extends BaseAdapter implements Filterable { + private static final String TAG = SearchAdapter.class.getSimpleName(); private static final Pattern SPACE_PATTERN = Pattern.compile(" ", Pattern.LITERAL); private final List mHistory = new ArrayList<>(5); private final List mBookmarks = new ArrayList<>(5); @@ -388,6 +390,11 @@ public class SearchAdapter extends BaseAdapter implements Filterable { HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setDoInput(true); connection.connect(); + if (connection.getResponseCode() >= HttpURLConnection.HTTP_MULT_CHOICE || + connection.getResponseCode() < HttpURLConnection.HTTP_OK) { + Log.e(TAG, "Search API Responded with code: " + connection.getResponseCode()); + return cacheFile; + } in = connection.getInputStream(); if (in != null) {