Skip to content

Commit

Permalink
fix: log non-200 indexer response body
Browse files Browse the repository at this point in the history
  • Loading branch information
Theodus committed Jan 6, 2025
1 parent c3f834d commit dc58d77
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/indexer_client.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use http::header::CONTENT_TYPE;
use http::{header::CONTENT_TYPE, StatusCode};
use reqwest::header::AUTHORIZATION;
use serde::{Deserialize, Serialize};
use thegraph_core::{
Expand Down Expand Up @@ -59,17 +59,19 @@ impl IndexerClient {
.body(query.to_string())
.send()
.await;
let response = match result.and_then(|r| r.error_for_status()) {
let response = match result {
Ok(response) => response,
Err(err) if err.is_timeout() => return Err(Timeout),
Err(err) => {
return match err.status() {
Some(status) => Err(BadResponse(status.as_u16().to_string())),
_ if err.is_connect() => Err(BadResponse("failed to connect".to_string())),
_ => Err(BadResponse(err.to_string())),
}
}
Err(e) if e.is_timeout() => return Err(Timeout),
Err(e) if e.is_connect() => return Err(BadResponse("failed to connect".to_string())),
Err(e) => return Err(BadResponse(e.to_string())),
};
let status = response.status();
if status != StatusCode::OK {
if let Ok(body) = response.text().await {
tracing::info!(status = status.as_u16(), indexer_err_response = body);
}
return Err(BadResponse(status.as_u16().to_string()));
}

#[derive(Debug, Deserialize)]
pub struct IndexerResponsePayload {
Expand Down

0 comments on commit dc58d77

Please sign in to comment.