mirror of
https://github.com/Qortal/qortal.git
synced 2025-05-08 02:37:58 +00:00
Better handling of RPC errors.
Previously, if an error was returned from an Electrum server (such as "server busy") it would throw a NetworkException that would be caught outside of the server loop and cause the entire request to fail. Instead of throwing an exception, I am now logging the error and returning null, in the same way we do for IOException and NoSuchElementException further up in the same method. This allows the caller - most likely connectedRpc() - to move on to the next server in the list and try again. This should fix an issue seen where a "server busy" response from a single server was essentially breaking our implementation, as we would give up altogether instead of trying another server.
This commit is contained in:
parent
3b6ba7641d
commit
112675c782
@ -653,18 +653,27 @@ public class ElectrumX extends BitcoinyBlockchainProvider {
|
|||||||
|
|
||||||
Object errorObj = responseJson.get("error");
|
Object errorObj = responseJson.get("error");
|
||||||
if (errorObj != null) {
|
if (errorObj != null) {
|
||||||
if (errorObj instanceof String)
|
if (errorObj instanceof String) {
|
||||||
throw new ForeignBlockchainException.NetworkException(String.format("Unexpected error message from ElectrumX RPC %s: %s", method, (String) errorObj), this.currentServer);
|
LOGGER.debug(String.format("Unexpected error message from ElectrumX RPC %s: %s", method, (String) errorObj), this.currentServer);
|
||||||
|
// Try another server
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
if (!(errorObj instanceof JSONObject))
|
if (!(errorObj instanceof JSONObject)) {
|
||||||
throw new ForeignBlockchainException.NetworkException(String.format("Unexpected error response from ElectrumX RPC %s", method), this.currentServer);
|
LOGGER.debug(String.format("Unexpected error response from ElectrumX RPC %s", method), this.currentServer);
|
||||||
|
// Try another server
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
JSONObject errorJson = (JSONObject) errorObj;
|
JSONObject errorJson = (JSONObject) errorObj;
|
||||||
|
|
||||||
Object messageObj = errorJson.get("message");
|
Object messageObj = errorJson.get("message");
|
||||||
|
|
||||||
if (!(messageObj instanceof String))
|
if (!(messageObj instanceof String)) {
|
||||||
throw new ForeignBlockchainException.NetworkException(String.format("Missing/invalid message in error response from ElectrumX RPC %s", method), this.currentServer);
|
LOGGER.debug(String.format("Missing/invalid message in error response from ElectrumX RPC %s", method), this.currentServer);
|
||||||
|
// Try another server
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
String message = (String) messageObj;
|
String message = (String) messageObj;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user