Skip to content

Commit

Permalink
Improve Etherscan API error handling (#3876)
Browse files Browse the repository at this point in the history
  • Loading branch information
kanewallmann authored Dec 14, 2022
1 parent 5ca6e6c commit 8fd5930
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions chisel/src/dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,8 @@ impl ChiselDisptacher {
match reqwest::get(&request_url).await {
Ok(response) => {
let json = response.json::<EtherscanABIResponse>().await.unwrap();
if let Some(abi) = json.result {
if json.status.eq("1") && json.result.is_some() {
let abi = json.result.unwrap();
if let Ok(abi) = ethers::abi::Abi::load(abi.as_bytes()) {
let mut interface = format!(
"// Interface of {}\ninterface {} {{\n",
Expand Down Expand Up @@ -570,9 +571,13 @@ impl ChiselDisptacher {
"Contract is not verified!",
))
}
} else if let Some(error_msg) = json.result {
DispatchResult::CommandFailed(Self::make_error(format!(
"Could not fetch interface - \"{error_msg}\""
)))
} else {
DispatchResult::CommandFailed(Self::make_error(format!(
"Coult not fetch interface - \"{}\"",
"Could not fetch interface - \"{}\"",
json.message
)))
}
Expand Down

0 comments on commit 8fd5930

Please sign in to comment.