mirror of
https://github.com/moparisthebest/open-keychain
synced 2025-02-25 16:01:52 -05:00
Even better Exception handling with keyserver queries
This commit is contained in:
parent
cc034a0913
commit
aa32c60a0a
@ -217,7 +217,7 @@ public class HkpKeyserver extends Keyserver {
|
|||||||
throw new HttpError(response, data);
|
throw new HttpError(response, data);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} 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 {
|
try {
|
||||||
data = query(request);
|
data = query(request);
|
||||||
} catch (HttpError e) {
|
} catch (HttpError e) {
|
||||||
if (e.getCode() == 404) {
|
if (e.getData() != null) {
|
||||||
throw new QueryFailedException("keyserver '" + mHost + "' not found. Error 404");
|
|
||||||
} else if (e.getData() != null) {
|
|
||||||
Log.d(Constants.TAG, "returned error data: " + e.getData().toLowerCase(Locale.US));
|
Log.d(Constants.TAG, "returned error data: " + e.getData().toLowerCase(Locale.US));
|
||||||
|
|
||||||
if (e.getData().toLowerCase(Locale.US).contains("no keys found")) {
|
if (e.getData().toLowerCase(Locale.US).contains("no keys found")) {
|
||||||
|
// NOTE: This is also a 404 error for some keyservers!
|
||||||
return results;
|
return results;
|
||||||
} else if (e.getData().toLowerCase(Locale.US).contains("too many")) {
|
} else if (e.getData().toLowerCase(Locale.US).contains("too many")) {
|
||||||
throw new TooManyResponsesException();
|
throw new TooManyResponsesException();
|
||||||
} else if (e.getData().toLowerCase(Locale.US).contains("insufficient")) {
|
} else if (e.getData().toLowerCase(Locale.US).contains("insufficient")) {
|
||||||
throw new QueryTooShortException();
|
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);
|
final Matcher matcher = PUB_KEY_LINE.matcher(data);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user