Skip to content

Commit 22f6f83

Browse files
committed
refactor: utilize QueryError for returning subgraph query errors
1 parent e0e37e8 commit 22f6f83

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

service/src/metrics/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ use axum::http::StatusCode;
66
use axum::routing::get;
77
use axum::Router;
88
use lazy_static::lazy_static;
9-
use prometheus::{
10-
register_histogram_vec, register_int_counter_vec, HistogramVec, IntCounterVec,
11-
};
9+
use prometheus::{register_histogram_vec, register_int_counter_vec, HistogramVec, IntCounterVec};
1210
use std::{net::SocketAddr, str::FromStr};
1311
use tracing::info;
1412

service/src/server/routes/subgraphs.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,32 +116,34 @@ pub async fn subgraph_queries(
116116
};
117117

118118
match server.query_processor.execute_paid_query(paid_query).await {
119-
Ok(res) if res.status == 200 => {
119+
Ok(res) => {
120120
query_duration_timer.observe_duration();
121121
metrics::SUCCESSFUL_QUERIES
122122
.with_label_values(&[&deployment_label])
123123
.inc();
124124
(StatusCode::OK, Json(res.result)).into_response()
125125
}
126-
_ => {
126+
Err(e) => {
127127
metrics::FAILED_QUERIES
128128
.with_label_values(&[&deployment_label])
129129
.inc();
130-
IndexerError::new(
131-
IndexerErrorCode::IE032,
132-
Some(IndexerErrorCause::new(
133-
"Failed to execute a paid subgraph query to graph node",
134-
)),
130+
let err_msg = format!(
131+
"Failed to execute a paid subgraph query to graph node: {}",
132+
e
135133
);
136-
return bad_request_response("Failed to execute paid query");
134+
IndexerError::new(IndexerErrorCode::IE032, Some(IndexerErrorCause::new(e)));
135+
return bad_request_response(&err_msg);
137136
}
138137
}
139138
} else {
140-
// TODO: emit IndexerErrorCode::IE030 on missing receipt
141139
let error_body = "Query request header missing scalar-receipts or incorrect auth token";
142140
metrics::QUERIES_WITHOUT_RECEIPT
143141
.with_label_values(&[&deployment_label])
144142
.inc();
143+
IndexerError::new(
144+
IndexerErrorCode::IE030,
145+
Some(IndexerErrorCause::new(error_body)),
146+
);
145147
query_duration_timer.observe_duration();
146148
bad_request_response(error_body)
147149
}

0 commit comments

Comments
 (0)