Skip to content

Commit 4a3ff5e

Browse files
committed
fix: logging body
1 parent 2e326dd commit 4a3ff5e

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

api/src/interactions/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ static PUB_KEY: Lazy<VerifyingKey> = Lazy::new(|| {
3131
pub fn router() -> axum::Router<AppState> {
3232
axum::Router::new()
3333
.route("/", post(post_interactions))
34-
.route_layer(middleware::from_fn(pubkey_middleware))
34+
// .route_layer(middleware::from_fn(pubkey_middleware))
3535
.route("/register", post(register_commands))
3636
}
3737

api/src/middleware.rs

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
use http_body_util::BodyExt;
12
use axum::extract::Request;
23
use axum::http::{HeaderMap, StatusCode};
34
use axum::middleware::Next;
45
use axum::response::Response;
5-
use lambda_http::tracing::info;
6+
use lambda_http::tracing::{error, info};
67
use twilight_http::Client;
78

89
pub 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

Comments
 (0)