Skip to content

Commit

Permalink
Add request error logging (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dzejkop authored Jun 11, 2024
1 parent 44fd113 commit bd16c17
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,8 @@ pub async fn spawn_server(app: Arc<App>) -> eyre::Result<ServerHandle> {
.nest("/schema.json", api_service.spec_endpoint())
.nest("/schema.yml", api_service.spec_endpoint_yaml())
.nest("/", api_service)
.with(Cors::new())
.with(trace_middleware::TraceMiddleware)
.with(Cors::new())
.data(app.clone());

let listener = TcpListener::bind(app.config.server.host);
Expand Down
9 changes: 8 additions & 1 deletion src/server/trace_middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,14 @@ impl<E: Endpoint> Endpoint for TraceMiddlwareImpl<E> {
let res = self.0.call(req).await;
let response = match res {
Ok(r) => r.into_response(),
Err(e) => e.into_response(),
Err(err) => {
let stacktrace = format!("{:?}", err);
let message = err.to_string();

tracing::error!(error.message = message, error.stack = stacktrace, error.kind = "Error", "error processing request");

err.into_response()
},
};

if response.status().is_server_error() {
Expand Down

0 comments on commit bd16c17

Please sign in to comment.