diff options
author | Dominik Schürmann <dominik@dominikschuermann.de> | 2014-07-31 18:07:11 +0200 |
---|---|---|
committer | Dominik Schürmann <dominik@dominikschuermann.de> | 2014-07-31 18:07:11 +0200 |
commit | aa32c60a0aca4ad35106bb98a214fc724ab090cd (patch) | |
tree | 41d0932d2dc8109f120b89c244640bad494f7f1c /OpenKeychain/src | |
parent | cc034a09139ba12e70baba5d8eb45aeb1318097b (diff) | |
download | open-keychain-aa32c60a0aca4ad35106bb98a214fc724ab090cd.tar.gz open-keychain-aa32c60a0aca4ad35106bb98a214fc724ab090cd.tar.bz2 open-keychain-aa32c60a0aca4ad35106bb98a214fc724ab090cd.zip |
Even better Exception handling with keyserver queries
Diffstat (limited to 'OpenKeychain/src')
-rw-r--r-- | OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/HkpKeyserver.java | 18 |
1 files changed, 10 insertions, 8 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 7f7d10319..f35ef45a2 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/HkpKeyserver.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/HkpKeyserver.java @@ -217,7 +217,7 @@ public class HkpKeyserver extends Keyserver { throw new HttpError(response, data); } } catch (IOException e) { - throw new QueryFailedException("querying server(s) for '" + mHost + "' failed"); + throw new QueryFailedException("Keyserver '" + mHost + "' is unavailable. Check your Internet connection!"); } } @@ -242,24 +242,26 @@ public class HkpKeyserver extends Keyserver { try { data = query(request); } catch (HttpError e) { - if (e.getCode() == 404) { - throw new QueryFailedException("keyserver '" + mHost + "' not found. Error 404"); - } else if (e.getData() != null) { + if (e.getData() != null) { Log.d(Constants.TAG, "returned error data: " + e.getData().toLowerCase(Locale.US)); if (e.getData().toLowerCase(Locale.US).contains("no keys found")) { + // NOTE: This is also a 404 error for some keyservers! return results; } else if (e.getData().toLowerCase(Locale.US).contains("too many")) { throw new TooManyResponsesException(); } else if (e.getData().toLowerCase(Locale.US).contains("insufficient")) { throw new QueryTooShortException(); + } else if (e.getCode() == 404) { + // NOTE: handle this 404 at last, maybe it was a "no keys found" error + throw new QueryFailedException("Keyserver '" + mHost + "' not found. Error 404"); + } else { + // NOTE: some keyserver do not provide a more detailed error response + throw new QueryFailedException("Either no keys or too many have been found. Please improve your query!"); } - - // NOTE: some keyserver do not provide a more detailed error response - throw new QueryFailedException("Either no keys or too many have been found. Please improve your query!"); } - throw new QueryFailedException("querying server(s) for '" + mHost + "' failed"); + throw new QueryFailedException("Querying server(s) for '" + mHost + "' failed."); } final Matcher matcher = PUB_KEY_LINE.matcher(data); |