1+ use http_body_util:: BodyExt ;
12use axum:: extract:: Request ;
23use axum:: http:: { HeaderMap , StatusCode } ;
34use axum:: middleware:: Next ;
45use axum:: response:: Response ;
5- use lambda_http:: tracing:: info;
6+ use lambda_http:: tracing:: { error , info} ;
67use twilight_http:: Client ;
78
89pub async fn auth_middleware (
@@ -34,14 +35,34 @@ pub async fn log_middleware(
3435 request : Request ,
3536 next : Next ,
3637) -> Result < Response , StatusCode > {
37- // Log the request
38- info ! ( "Received request: {:?}" , request) ;
39-
38+ let ( parts, body) = request. into_parts ( ) ;
39+ let body = body
40+ . collect ( )
41+ . await
42+ . map_err ( |e| {
43+ error ! ( "Internal Server Error: {:?}" , e) ;
44+ StatusCode :: INTERNAL_SERVER_ERROR
45+ } ) ?
46+ . to_bytes ( ) ;
47+
48+ info ! ( "Received request: {:?} {:?}" , parts, body) ;
49+
4050 // Call the next middleware or handler
41- let response = next. run ( request) . await ;
51+ let response = next. run ( Request :: from_parts ( parts, axum:: body:: Body :: from ( body) ) ) . await ;
52+
53+
54+ let ( parts, body) = response. into_parts ( ) ;
55+ let body = body
56+ . collect ( )
57+ . await
58+ . map_err ( |e| {
59+ error ! ( "Internal Server Error: {:?}" , e) ;
60+ StatusCode :: INTERNAL_SERVER_ERROR
61+ } ) ?
62+ . to_bytes ( ) ;
4263
4364 // Log the response
44- info ! ( "Response: {:?}" , response ) ;
65+ info ! ( "Response: {:?} {:?}" , parts , body ) ;
4566
46- Ok ( response )
67+ Ok ( Response :: from_parts ( parts , axum :: body :: Body :: from ( body ) ) )
4768}
0 commit comments