Skip to content

Commit

Permalink
return something more sane if fund fails
Browse files Browse the repository at this point in the history
  • Loading branch information
josh-richardson committed Feb 26, 2020
1 parent b4b6185 commit 72d248e
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/main/java/org/web3j/console/WalletFunder.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,20 +171,22 @@ public static String fundWallet(String walletAddress, Faucet faucet, String toke
.post(fundingBody)
.build();
}
try {
Response sendRawResponse = client.newCall(sendEtherRequest).execute();

Response sendRawResponse = client.newCall(sendEtherRequest).execute();

if (sendRawResponse.code() != 200) {
exitError(
String.format(
"\nAn HTTP request failed with code: %d", sendRawResponse.code()));
}

String sendResponse = sendRawResponse.body().string();
if (sendRawResponse.code() != 200) {
exitError(
String.format(
"\nAn HTTP request failed with code: %d", sendRawResponse.code()));
}

WalletFunderResult result = mapper.readValue(sendResponse, WalletFunderResult.class);
String sendResponse = sendRawResponse.body().string();

return result.result;
WalletFunderResult result = mapper.readValue(sendResponse, WalletFunderResult.class);
return result.result;
} catch (Exception ex) {
return "The fund operation failed - this may be due to an issue with the remote server. Please try again.";
}
}
}

Expand Down

0 comments on commit 72d248e

Please sign in to comment.