File tree Expand file tree Collapse file tree 3 files changed +18
-7
lines changed Expand file tree Collapse file tree 3 files changed +18
-7
lines changed Original file line number Diff line number Diff line change @@ -40,18 +40,19 @@ pub enum IndexerServiceError {
4040// Helper struct to properly format
4141// error messages
4242#[ derive( Serialize ) ]
43- struct ErrorResponse {
44- message : String ,
43+ #[ cfg_attr( test, derive( serde:: Deserialize ) ) ]
44+ pub struct ErrorResponse {
45+ pub ( crate ) message : String ,
4546}
4647
4748impl ErrorResponse {
48- fn new ( message : impl ToString ) -> Self {
49+ pub fn new ( message : impl ToString ) -> Self {
4950 Self {
5051 message : message. to_string ( ) ,
5152 }
5253 }
5354
54- fn into_response ( self , status_code : StatusCode ) -> Response {
55+ pub fn into_response ( self , status_code : StatusCode ) -> Response {
5556 ( status_code, Json ( self ) ) . into_response ( )
5657 }
5758}
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ use reqwest::StatusCode;
1414use serde:: Serialize ;
1515use thegraph_core:: attestation:: Attestation ;
1616
17- use crate :: error:: StatusCodeExt ;
17+ use crate :: error:: { ErrorResponse , StatusCodeExt } ;
1818
1919#[ derive( Clone ) ]
2020pub enum AttestationInput {
@@ -56,6 +56,11 @@ pub async fn attestation_middleware(
5656 ( Some ( signer) , Some ( AttestationInput :: Attestable { req } ) ) => {
5757 Some ( signer. create_attestation ( req, & res) )
5858 }
59+ ( None , Some ( AttestationInput :: Attestable { .. } ) ) => {
60+ // keep this branch separated just to log the missing signer condition
61+ tracing:: warn!( "Attestation requested but no signer found" ) ;
62+ None
63+ }
5964 _ => None ,
6065 } ;
6166
@@ -93,12 +98,14 @@ impl StatusCodeExt for AttestationError {
9398
9499impl IntoResponse for AttestationError {
95100 fn into_response ( self ) -> Response {
96- self . status_code ( ) . into_response ( )
101+ tracing:: error!( error=%self , "Attestation error" ) ;
102+ let status_code = self . status_code ( ) ;
103+ ErrorResponse :: new ( self ) . into_response ( status_code)
97104 }
98105}
99106
100107#[ cfg( test) ]
101- mod tests {
108+ mod attestation_tests {
102109 use axum:: {
103110 body:: { to_bytes, Body } ,
104111 http:: { Request , Response } ,
Original file line number Diff line number Diff line change @@ -30,6 +30,9 @@ pub async fn signer_middleware(
3030 if let Some ( Allocation ( allocation_id) ) = request. extensions ( ) . get :: < Allocation > ( ) {
3131 if let Some ( signer) = state. attestation_signers . borrow ( ) . get ( allocation_id) {
3232 request. extensions_mut ( ) . insert ( signer. clone ( ) ) ;
33+ } else {
34+ // Just log this case which is silently passed through next middleware
35+ tracing:: warn!( %allocation_id, "No attestation signer found for allocation" , ) ;
3336 }
3437 }
3538
You can’t perform that action at this time.
0 commit comments