Skip to content

Commit

Permalink
LogMiddleware: do something with res.error()
Browse files Browse the repository at this point in the history
Makes use of the newly updated error propgation from
`Response: add optional error storage` for a more
informative error case in the log middleware.
  • Loading branch information
Fishrock123 committed Jul 7, 2020
1 parent fd279e1 commit 77ddda2
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/log/middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,22 @@ impl LogMiddleware {
let response = next.run(ctx).await;
let status = response.status();
if status.is_server_error() {
log::error!("--> Response sent", {
method: method,
path: path,
status: status as u16,
duration: format!("{:?}", start.elapsed()),
});
if let Some(error) = response.error() {
log::error!("Internal error --> Response sent", {
message: error.to_string(),
method: method,
path: path,
status: status as u16,
duration: format!("{:?}", start.elapsed()),
});
} else {
log::error!("Internal error --> Response sent", {
method: method,
path: path,
status: status as u16,
duration: format!("{:?}", start.elapsed()),
});
}
} else if status.is_client_error() {
log::warn!("--> Response sent", {
method: method,
Expand Down

0 comments on commit 77ddda2

Please sign in to comment.