Skip to content

Commit

Permalink
refactor: utilize QueryError for returning subgraph query errors
Browse files Browse the repository at this point in the history
  • Loading branch information
hopeyen committed Nov 4, 2023
1 parent e0e37e8 commit 22f6f83
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
4 changes: 1 addition & 3 deletions service/src/metrics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ use axum::http::StatusCode;
use axum::routing::get;
use axum::Router;
use lazy_static::lazy_static;
use prometheus::{
register_histogram_vec, register_int_counter_vec, HistogramVec, IntCounterVec,
};
use prometheus::{register_histogram_vec, register_int_counter_vec, HistogramVec, IntCounterVec};
use std::{net::SocketAddr, str::FromStr};
use tracing::info;

Expand Down
20 changes: 11 additions & 9 deletions service/src/server/routes/subgraphs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,32 +116,34 @@ pub async fn subgraph_queries(
};

match server.query_processor.execute_paid_query(paid_query).await {
Ok(res) if res.status == 200 => {
Ok(res) => {
query_duration_timer.observe_duration();
metrics::SUCCESSFUL_QUERIES
.with_label_values(&[&deployment_label])
.inc();
(StatusCode::OK, Json(res.result)).into_response()
}
_ => {
Err(e) => {
metrics::FAILED_QUERIES
.with_label_values(&[&deployment_label])
.inc();
IndexerError::new(
IndexerErrorCode::IE032,
Some(IndexerErrorCause::new(
"Failed to execute a paid subgraph query to graph node",
)),
let err_msg = format!(
"Failed to execute a paid subgraph query to graph node: {}",
e
);
return bad_request_response("Failed to execute paid query");
IndexerError::new(IndexerErrorCode::IE032, Some(IndexerErrorCause::new(e)));
return bad_request_response(&err_msg);
}
}
} else {
// TODO: emit IndexerErrorCode::IE030 on missing receipt
let error_body = "Query request header missing scalar-receipts or incorrect auth token";
metrics::QUERIES_WITHOUT_RECEIPT
.with_label_values(&[&deployment_label])
.inc();
IndexerError::new(
IndexerErrorCode::IE030,
Some(IndexerErrorCause::new(error_body)),
);
query_duration_timer.observe_duration();
bad_request_response(error_body)
}
Expand Down

0 comments on commit 22f6f83

Please sign in to comment.