diff options
author | Tim Bray <timbray@gmail.com> | 2014-05-22 16:56:28 -0700 |
---|---|---|
committer | Tim Bray <timbray@gmail.com> | 2014-05-23 09:33:34 -0700 |
commit | dfd5aa65a54941261b7a2ee19fedd99ee0e9607b (patch) | |
tree | b8c7fec113f27d7a55a578b028928362aa4cc893 /OpenKeychain/src/main/java/org/sufficientlysecure/keychain | |
parent | 8a2ffd8f90e9653ed69f945a94f6b9702dbdfff4 (diff) | |
download | open-keychain-dfd5aa65a54941261b7a2ee19fedd99ee0e9607b.tar.gz open-keychain-dfd5aa65a54941261b7a2ee19fedd99ee0e9607b.tar.bz2 open-keychain-dfd5aa65a54941261b7a2ee19fedd99ee0e9607b.zip |
Add Log.d for QueryFailedException
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain')
6 files changed, 25 insertions, 37 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/HkpKeyserver.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/HkpKeyserver.java index f14978b39..202b750e4 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/HkpKeyserver.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/HkpKeyserver.java @@ -200,12 +200,12 @@ public class HkpKeyserver extends Keyserver { } @Override - public ArrayList<ImportKeysListEntry> search(String query) throws QueryException, TooManyResponses, - InsufficientQuery { + public ArrayList<ImportKeysListEntry> search(String query) throws QueryException, + QueryNeedsRepairException { ArrayList<ImportKeysListEntry> results = new ArrayList<ImportKeysListEntry>(); if (query.length() < 3) { - throw new InsufficientQuery(); + throw new QueryTooShortException(); } String encodedQuery; @@ -226,9 +226,9 @@ public class HkpKeyserver extends Keyserver { if (e.getData().toLowerCase(Locale.US).contains("no keys found")) { return results; } else if (e.getData().toLowerCase(Locale.US).contains("too many")) { - throw new TooManyResponses(); + throw new TooManyResponsesException(); } else if (e.getData().toLowerCase(Locale.US).contains("insufficient")) { - throw new InsufficientQuery(); + throw new QueryTooShortException(); } } throw new QueryException("querying server(s) for '" + mHost + "' failed"); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/KeybaseKeyserver.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/KeybaseKeyserver.java index 5b66b50c5..ec4b61671 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/KeybaseKeyserver.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/KeybaseKeyserver.java @@ -34,8 +34,8 @@ public class KeybaseKeyserver extends Keyserver { private String mQuery; @Override - public ArrayList<ImportKeysListEntry> search(String query) throws QueryException, TooManyResponses, - InsufficientQuery { + public ArrayList<ImportKeysListEntry> search(String query) throws QueryException, + QueryNeedsRepairException { ArrayList<ImportKeysListEntry> results = new ArrayList<ImportKeysListEntry>(); if (query.startsWith("0x")) { @@ -84,6 +84,7 @@ public class KeybaseKeyserver extends Keyserver { } private ImportKeysListEntry makeEntry(JSONObject match) throws QueryException, JSONException { + final ImportKeysListEntry entry = new ImportKeysListEntry(); entry.setQuery(mQuery); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/Keyserver.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/Keyserver.java index 19591eda8..7313a159b 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/Keyserver.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/Keyserver.java @@ -32,20 +32,23 @@ public abstract class Keyserver { } } - public static class TooManyResponses extends Exception { + public static class QueryNeedsRepairException extends Exception { + private static final long serialVersionUID = 2693768928624654512L; + } + + public static class TooManyResponsesException extends QueryNeedsRepairException { private static final long serialVersionUID = 2703768928624654513L; } - public static class InsufficientQuery extends Exception { - private static final long serialVersionUID = 2703768928624654514L; + public static class QueryTooShortException extends QueryNeedsRepairException { } public static class AddKeyException extends Exception { private static final long serialVersionUID = -507574859137295530L; } - abstract List<ImportKeysListEntry> search(String query) throws QueryException, TooManyResponses, - InsufficientQuery; + abstract List<ImportKeysListEntry> search(String query) throws QueryException, + QueryNeedsRepairException; abstract String get(String keyIdHex) throws QueryException; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java index e93d717e1..9c05dcc65 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java @@ -273,38 +273,28 @@ public class ImportKeysListFragment extends ListFragment implements break; case LOADER_ID_SERVER_QUERY: + case LOADER_ID_KEYBASE: + // TODO: possibly fine-tune message building for these two cases if (error == null) { AppMsg.makeText( getActivity(), getResources().getQuantityString(R.plurals.keys_found, mAdapter.getCount(), mAdapter.getCount()), AppMsg.STYLE_INFO ).show(); - } else if (error instanceof Keyserver.InsufficientQuery) { + } else if (error instanceof Keyserver.QueryTooShortException) { AppMsg.makeText(getActivity(), R.string.error_keyserver_insufficient_query, AppMsg.STYLE_ALERT).show(); } else if (error instanceof Keyserver.QueryException) { - AppMsg.makeText(getActivity(), R.string.error_keyserver_query, - AppMsg.STYLE_ALERT).show(); - } else if (error instanceof Keyserver.TooManyResponses) { + String alert = getActivity().getString(R.string.error_searching_keys); + alert = alert + " (" + error.getLocalizedMessage() + ")"; + AppMsg.makeText(getActivity(), alert, AppMsg.STYLE_ALERT).show(); + } else if (error instanceof Keyserver.TooManyResponsesException) { AppMsg.makeText(getActivity(), R.string.error_keyserver_too_many_responses, AppMsg.STYLE_ALERT).show(); } break; - case LOADER_ID_KEYBASE: - - if (error == null) { - AppMsg.makeText( - getActivity(), getResources().getQuantityString(R.plurals.keys_found, - mAdapter.getCount(), mAdapter.getCount()), - AppMsg.STYLE_INFO - ).show(); - } else if (error instanceof Keyserver.QueryException) { - AppMsg.makeText(getActivity(), R.string.error_keyserver_query, - AppMsg.STYLE_ALERT).show(); - } - default: break; } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListKeybaseLoader.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListKeybaseLoader.java index 0fdc019d0..3f15e64f0 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListKeybaseLoader.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListKeybaseLoader.java @@ -94,14 +94,10 @@ public class ImportKeysListKeybaseLoader mEntryList.addAll(searchResult); mEntryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>(mEntryList, null); - } catch (Keyserver.InsufficientQuery e) { - mEntryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>(mEntryList, e); } catch (Keyserver.QueryException e) { mEntryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>(mEntryList, e); - } catch (Keyserver.TooManyResponses e) { + } catch (Keyserver.QueryNeedsRepairException e) { mEntryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>(mEntryList, e); } - } - } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListServerLoader.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListServerLoader.java index 1b8d7d30e..4b2af14a9 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListServerLoader.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListServerLoader.java @@ -116,11 +116,9 @@ public class ImportKeysListServerLoader mEntryList.addAll(searchResult); } mEntryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>(mEntryList, null); - } catch (Keyserver.InsufficientQuery e) { - mEntryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>(mEntryList, e); } catch (Keyserver.QueryException e) { mEntryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>(mEntryList, e); - } catch (Keyserver.TooManyResponses e) { + } catch (Keyserver.QueryNeedsRepairException e) { mEntryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>(mEntryList, e); } } |