@@ -45,19 +45,17 @@ pub async fn attestation_middleware(
4545 request : Request ,
4646 next : Next ,
4747) -> Result < Response , AttestationError > {
48- let signer = request
49- . extensions ( )
50- . get :: < AttestationSigner > ( )
51- . cloned ( )
52- . ok_or ( AttestationError :: CouldNotFindSigner ) ?;
48+ let signer = request. extensions ( ) . get :: < AttestationSigner > ( ) . cloned ( ) ;
5349
5450 let ( parts, graphql_response) = next. run ( request) . await . into_parts ( ) ;
5551 let attestation_response = parts. extensions . get :: < AttestationInput > ( ) ;
5652 let bytes = to_bytes ( graphql_response, usize:: MAX ) . await ?;
5753 let res = String :: from_utf8 ( bytes. into ( ) ) ?;
5854
59- let attestation = match attestation_response {
60- Some ( AttestationInput :: Attestable { req } ) => Some ( signer. create_attestation ( req, & res) ) ,
55+ let attestation = match ( signer, attestation_response) {
56+ ( Some ( signer) , Some ( AttestationInput :: Attestable { req } ) ) => {
57+ Some ( signer. create_attestation ( req, & res) )
58+ }
6159 _ => None ,
6260 } ;
6361
@@ -73,26 +71,22 @@ pub async fn attestation_middleware(
7371
7472#[ derive( thiserror:: Error , Debug ) ]
7573pub enum AttestationError {
76- #[ error( "Could not find signer for allocation" ) ]
77- CouldNotFindSigner ,
78-
7974 #[ error( "There was an AxumError: {0}" ) ]
80- AxumError ( #[ from] axum:: Error ) ,
75+ Axum ( #[ from] axum:: Error ) ,
8176
8277 #[ error( "There was an error converting the response to UTF-8 string: {0}" ) ]
83- FromUtf8Error ( #[ from] FromUtf8Error ) ,
78+ FromUtf8 ( #[ from] FromUtf8Error ) ,
8479
8580 #[ error( "there was an error while serializing the response: {0}" ) ]
86- SerializationError ( #[ from] serde_json:: Error ) ,
81+ Serialization ( #[ from] serde_json:: Error ) ,
8782}
8883
8984impl StatusCodeExt for AttestationError {
9085 fn status_code ( & self ) -> StatusCode {
9186 match self {
92- AttestationError :: CouldNotFindSigner => StatusCode :: INTERNAL_SERVER_ERROR ,
93- AttestationError :: AxumError ( _)
94- | AttestationError :: FromUtf8Error ( _)
95- | AttestationError :: SerializationError ( _) => StatusCode :: BAD_GATEWAY ,
87+ AttestationError :: Axum ( _)
88+ | AttestationError :: FromUtf8 ( _)
89+ | AttestationError :: Serialization ( _) => StatusCode :: BAD_GATEWAY ,
9690 }
9791 }
9892}
@@ -211,6 +205,6 @@ mod tests {
211205 let app = Router :: new ( ) . route ( "/" , get ( handle) ) . layer ( middleware) ;
212206
213207 let res = send_request ( app, None ) . await ;
214- assert_eq ! ( res. status( ) , StatusCode :: INTERNAL_SERVER_ERROR ) ;
208+ assert_eq ! ( res. status( ) , StatusCode :: OK ) ;
215209 }
216210}
0 commit comments