Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
chore: error with EmptyResult instead of always letting serde error
Browse files Browse the repository at this point in the history
  • Loading branch information
Evalir committed May 22, 2023
1 parent 03680fa commit 94ad922
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 9 additions & 1 deletion ethers-etherscan/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,15 @@ impl Client {
let query = self.create_query("contract", "getabi", HashMap::from([("address", address)]));
let resp: Response<Option<String>> = self.get_json(&query).await?;

let result = resp.result.unwrap_or("".to_string());
let result = match resp.result {
Some(result) => result,
None => {
return Err(EtherscanError::EmptyResult {
message: resp.message,
status: resp.status,
})
}
};

if result.starts_with("Max rate limit reached") {
return Err(EtherscanError::RateLimitExceeded)
Expand Down
2 changes: 2 additions & 0 deletions ethers-etherscan/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ pub enum EtherscanError {
Serde(#[from] serde_json::Error),
#[error("Contract source code not verified: {0}")]
ContractCodeNotVerified(Address),
#[error("Response result is unexpectedly empty")]
EmptyResult { status: String, message: String },
#[error("Rate limit exceeded")]
RateLimitExceeded,
#[error(transparent)]
Expand Down

0 comments on commit 94ad922

Please sign in to comment.