From 8fd5930c74d352bb8e8c7dffc3e7fd7839ecb535 Mon Sep 17 00:00:00 2001 From: Kane Wallmann <57159130+kanewallmann@users.noreply.github.com> Date: Wed, 14 Dec 2022 18:07:32 +1000 Subject: [PATCH] Improve Etherscan API error handling (#3876) --- chisel/src/dispatcher.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/chisel/src/dispatcher.rs b/chisel/src/dispatcher.rs index edb91279162c..662637d723d9 100644 --- a/chisel/src/dispatcher.rs +++ b/chisel/src/dispatcher.rs @@ -481,7 +481,8 @@ impl ChiselDisptacher { match reqwest::get(&request_url).await { Ok(response) => { let json = response.json::().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", @@ -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 ))) }