diff --git a/crates/service/src/error.rs b/crates/service/src/error.rs index 586337df4..5bf9ab4d7 100644 --- a/crates/service/src/error.rs +++ b/crates/service/src/error.rs @@ -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() } } diff --git a/crates/service/src/middleware/attestation.rs b/crates/service/src/middleware/attestation.rs index 92da663e9..5a9e40726 100644 --- a/crates/service/src/middleware/attestation.rs +++ b/crates/service/src/middleware/attestation.rs @@ -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 { @@ -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, }; @@ -93,12 +98,14 @@ impl StatusCodeExt for AttestationError { impl IntoResponse for AttestationError { fn into_response(self) -> Response { - self.status_code().into_response() + tracing::error!(error=%self, "Attestation error"); + 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}, diff --git a/crates/service/src/middleware/attestation_signer.rs b/crates/service/src/middleware/attestation_signer.rs index f59be7ebd..1a71d3d57 100644 --- a/crates/service/src/middleware/attestation_signer.rs +++ b/crates/service/src/middleware/attestation_signer.rs @@ -30,6 +30,9 @@ pub async fn signer_middleware( if let Some(Allocation(allocation_id)) = request.extensions().get::() { 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!(%allocation_id, "No attestation signer found for allocation",); } }