diff --git a/nft_ingester/src/error/mod.rs b/nft_ingester/src/error/mod.rs index 80b132f70..eca96f5df 100644 --- a/nft_ingester/src/error/mod.rs +++ b/nft_ingester/src/error/mod.rs @@ -48,6 +48,8 @@ pub enum IngesterError { UnrecoverableTaskError, #[error("Cache Storage Write Error {0}")] CacheStorageWriteError(String), + #[error("HttpError {status_code}")] + HttpError { status_code: String }, } impl From for IngesterError { diff --git a/nft_ingester/src/tasks/common/mod.rs b/nft_ingester/src/tasks/common/mod.rs index 1389c91f9..7dd6944f6 100644 --- a/nft_ingester/src/tasks/common/mod.rs +++ b/nft_ingester/src/tasks/common/mod.rs @@ -55,12 +55,16 @@ impl DownloadMetadataTask { let client = ClientBuilder::new() .timeout(Duration::from_secs(3)) .build()?; - let val: serde_json::Value = Client::get(&client, uri) // Need to check for malicious sites ? + let response = Client::get(&client, uri) // Need to check for malicious sites ? .send() - .await? - .json() .await?; - Ok(val) + + if response.status() != reqwest::StatusCode::OK { + Err(IngesterError::HttpError{ status_code: response.status().as_str().to_string() }) + } else { + let val: serde_json::Value = response.json().await?; + Ok(val) + } } } diff --git a/nft_ingester/src/tasks/mod.rs b/nft_ingester/src/tasks/mod.rs index af25cf150..f12b6fa18 100644 --- a/nft_ingester/src/tasks/mod.rs +++ b/nft_ingester/src/tasks/mod.rs @@ -123,18 +123,29 @@ impl TaskManager { task.errors = Set(Some(e.to_string())); task.locked_until = Set(None); - if e == IngesterError::BatchInitNetworkingError { - // Network errors are common for off-chain JSONs. - // Logging these as errors is far too noisy. - metric! { - statsd_count!("ingester.bgtask.network_error", 1, "type" => task_name); - } - warn!("Task failed due to network error: {}", e); - } else { - metric! { - statsd_count!("ingester.bgtask.error", 1, "type" => task_name); + match e { + IngesterError::BatchInitNetworkingError => { + // Network errors are common for off-chain JSONs. + // Logging these as errors is far too noisy. + metric! { + statsd_count!("ingester.bgtask.network_error", 1, "type" => task_name); + } + warn!("Task failed due to network error: {}", e); + }, + IngesterError::HttpError { ref status_code } => { + metric! { + statsd_count!("ingester.bgtask.http_error", 1, + "status" => &status_code, + "type" => task_name); + } + warn!("Task failed due to HTTP error: {}", e); + }, + _ => { + metric! { + statsd_count!("ingester.bgtask.error", 1, "type" => task_name); + } + error!("Task Run Error: {}", e); } - error!("Task Run Error: {}", e); } } }