Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions crates/service/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,19 @@ pub enum IndexerServiceError {
// Helper struct to properly format
// error messages
#[derive(Serialize)]
struct ErrorResponse {
message: String,
#[cfg_attr(test, derive(serde::Deserialize))]
pub struct ErrorResponse {
pub(crate) message: String,
}

impl ErrorResponse {
fn new(message: impl ToString) -> Self {
pub fn new(message: impl ToString) -> Self {
Self {
message: message.to_string(),
}
}

fn into_response(self, status_code: StatusCode) -> Response {
pub fn into_response(self, status_code: StatusCode) -> Response {
(status_code, Json(self)).into_response()
}
}
Expand Down
13 changes: 10 additions & 3 deletions crates/service/src/middleware/attestation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use reqwest::StatusCode;
use serde::Serialize;
use thegraph_core::attestation::Attestation;

use crate::error::StatusCodeExt;
use crate::error::{ErrorResponse, StatusCodeExt};

#[derive(Clone)]
pub enum AttestationInput {
Expand Down Expand Up @@ -56,6 +56,11 @@ pub async fn attestation_middleware(
(Some(signer), Some(AttestationInput::Attestable { req })) => {
Some(signer.create_attestation(req, &res))
}
(None, Some(AttestationInput::Attestable { .. })) => {
// keep this branch separated just to log the missing signer condition
tracing::warn!("Attestation requested but no signer found");
None
}
_ => None,
};

Expand Down Expand Up @@ -93,12 +98,14 @@ impl StatusCodeExt for AttestationError {

impl IntoResponse for AttestationError {
fn into_response(self) -> Response {
self.status_code().into_response()
tracing::error!("Attestation error: {}", self);
let status_code = self.status_code();
ErrorResponse::new(self).into_response(status_code)
}
}

#[cfg(test)]
mod tests {
mod attestation_tests {
use axum::{
body::{to_bytes, Body},
http::{Request, Response},
Expand Down
6 changes: 6 additions & 0 deletions crates/service/src/middleware/attestation_signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ pub async fn signer_middleware(
if let Some(Allocation(allocation_id)) = request.extensions().get::<Allocation>() {
if let Some(signer) = state.attestation_signers.borrow().get(allocation_id) {
request.extensions_mut().insert(signer.clone());
} else {
// Just log this case which is silently passed through next middleware
tracing::warn!(
"No attestation signer found for allocation {}",
allocation_id
);
}
}

Expand Down
Loading