chore: add etherscan page not found error (#2126)

This commit is contained in:
Matthias Seitz 2023-02-10 20:51:13 +01:00 committed by GitHub
parent 060e145ea2
commit 64f2ca696f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 1 deletions

View File

@ -41,6 +41,8 @@ pub enum EtherscanError {
BlockedByCloudflare, BlockedByCloudflare,
#[error("The Requested prompted a cloudflare captcha security challenge to review the security of your connection before proceeding.")] #[error("The Requested prompted a cloudflare captcha security challenge to review the security of your connection before proceeding.")]
CloudFlareSecurityChallenge, 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 <https://community.cloudflare.com/t/sorry-you-have-been-blocked/110790> /// etherscan/polyscan is protected by cloudflare, which can lead to html responses like `Sorry, you have been blocked` See also <https://community.cloudflare.com/t/sorry-you-have-been-blocked/110790>

View File

@ -207,7 +207,9 @@ impl Client {
let res = res.as_ref(); let res = res.as_ref();
let res: ResponseData<T> = serde_json::from_str(res).map_err(|err| { let res: ResponseData<T> = serde_json::from_str(res).map_err(|err| {
error!(target: "etherscan", ?res, "Failed to deserialize response: {}", 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 EtherscanError::BlockedByCloudflare
} else if is_cloudflare_security_challenge(res) { } else if is_cloudflare_security_challenge(res) {
EtherscanError::CloudFlareSecurityChallenge EtherscanError::CloudFlareSecurityChallenge