From 64f2ca696fa60df11e58dbd64a715ea0d07c7b7c Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Fri, 10 Feb 2023 20:51:13 +0100 Subject: [PATCH] chore: add etherscan page not found error (#2126) --- ethers-etherscan/src/errors.rs | 2 ++ ethers-etherscan/src/lib.rs | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ethers-etherscan/src/errors.rs b/ethers-etherscan/src/errors.rs index f10920ba..f6cc587d 100644 --- a/ethers-etherscan/src/errors.rs +++ b/ethers-etherscan/src/errors.rs @@ -41,6 +41,8 @@ pub enum EtherscanError { BlockedByCloudflare, #[error("The Requested prompted a cloudflare captcha security challenge to review the security of your connection before proceeding.")] CloudFlareSecurityChallenge, + #[error("Received `Page not found` response. API server is likely down")] + PageNotFound, } /// etherscan/polyscan is protected by cloudflare, which can lead to html responses like `Sorry, you have been blocked` See also diff --git a/ethers-etherscan/src/lib.rs b/ethers-etherscan/src/lib.rs index b3fa1c6e..ee8437b6 100644 --- a/ethers-etherscan/src/lib.rs +++ b/ethers-etherscan/src/lib.rs @@ -207,7 +207,9 @@ impl Client { let res = res.as_ref(); let res: ResponseData = serde_json::from_str(res).map_err(|err| { error!(target: "etherscan", ?res, "Failed to deserialize response: {}", err); - if is_blocked_by_cloudflare_response(res) { + if res == "Page not found" { + EtherscanError::PageNotFound + } else if is_blocked_by_cloudflare_response(res) { EtherscanError::BlockedByCloudflare } else if is_cloudflare_security_challenge(res) { EtherscanError::CloudFlareSecurityChallenge