Merge pull request #6977 from AlphaWallet/log-rate-limited-blockscan-calls

[Explorer] Log rate limited blockscan API calls
pull/6978/head
Hwee-Boon Yar 1 year ago committed by GitHub
commit 6264e27248
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      modules/AlphaWalletFoundation/AlphaWalletFoundation/Tokens/Logic/EtherscanCompatibleBlockchainExplorer.swift
  2. 18
      modules/AlphaWalletFoundation/AlphaWalletFoundation/Transactions/BlockscoutBlockchainExplorer.swift

@ -338,6 +338,7 @@ class EtherscanCompatibleBlockchainExplorer: BlockchainExplorer {
analytics.log(error: Analytics.WebApiErrors.blockchainExplorerError, properties: properties)
case .success:
if let json = try? JSON(response.data) {
//Etherscan doesn't return 429
if json["result"].stringValue == "Max rate limit reached" {
infoLog("[API] request rate limited with status code: \(response.response.statusCode), json: \(json), server: \(server)", callerFunctionName: caller)
let properties: [String: AnalyticsEventPropertyValue] = [Analytics.Properties.chain.rawValue: server.chainID, Analytics.Properties.domainName.rawValue: domainName, Analytics.Properties.code.rawValue: response.response.statusCode]

@ -280,13 +280,19 @@ class BlockscoutBlockchainExplorer: BlockchainExplorer {
switch URLRequest.validate(statusCode: 200..<300, response: response.response) {
case .failure:
let json = try? JSON(response.data)
infoLog("[API] request failure with status code: \(response.response.statusCode), json: \(json), server: \(server)", callerFunctionName: caller)
var properties: [String: AnalyticsEventPropertyValue] = [Analytics.Properties.chain.rawValue: server.chainID, Analytics.Properties.domainName.rawValue: domainName, Analytics.Properties.code.rawValue: response.response.statusCode]
//Take `message` instead of `result` (different from Etherscan-compatible)
if let message = json?["message"].stringValue, !message.isEmpty {
properties[Analytics.Properties.message.rawValue] = message
if response.response.statusCode == 429 {
infoLog("[API] request rate limited with status code: \(response.response.statusCode), json: \(json), server: \(server)", callerFunctionName: caller)
let properties: [String: AnalyticsEventPropertyValue] = [Analytics.Properties.chain.rawValue: server.chainID, Analytics.Properties.domainName.rawValue: domainName, Analytics.Properties.code.rawValue: response.response.statusCode]
analytics.log(error: Analytics.WebApiErrors.blockchainExplorerRateLimited, properties: properties)
} else {
infoLog("[API] request failure with status code: \(response.response.statusCode), json: \(json), server: \(server)", callerFunctionName: caller)
var properties: [String: AnalyticsEventPropertyValue] = [Analytics.Properties.chain.rawValue: server.chainID, Analytics.Properties.domainName.rawValue: domainName, Analytics.Properties.code.rawValue: response.response.statusCode]
//Take `message` instead of `result` (different from Etherscan-compatible)
if let message = json?["message"].stringValue, !message.isEmpty {
properties[Analytics.Properties.message.rawValue] = message
}
analytics.log(error: Analytics.WebApiErrors.blockchainExplorerError, properties: properties)
}
analytics.log(error: Analytics.WebApiErrors.blockchainExplorerError, properties: properties)
case .success:
break
}

Loading…
Cancel
Save