Skip to content

Commit d0966b9

Browse files
authored
Merge pull request #721 from Fishrock123/logger-error-backtrace
Logger: properly print debug from errors
2 parents daa1702 + c5854fb commit d0966b9

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

examples/error_handling.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ async fn main() -> Result<()> {
1111
app.with(After(|mut res: Response| async {
1212
if let Some(err) = res.downcast_error::<async_std::io::Error>() {
1313
if let ErrorKind::NotFound = err.kind() {
14-
let msg = err.to_string();
14+
let msg = format!("Error: {:?}", err);
1515
res.set_status(StatusCode::NotFound);
1616

1717
// NOTE: You may want to avoid sending error messages in a production server.
18-
res.set_body(format!("Error: {}", msg));
18+
res.set_body(msg);
1919
}
2020
}
2121
Ok(res)

src/log/middleware.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ impl LogMiddleware {
5050
if status.is_server_error() {
5151
if let Some(error) = response.error() {
5252
log::error!("Internal error --> Response sent", {
53-
message: format!("\"{}\"", error.to_string()),
53+
message: format!("{:?}", error),
54+
error_type: error.type_name(),
5455
method: method,
5556
path: path,
5657
status: format!("{} - {}", status as u16, status.canonical_reason()),
@@ -67,7 +68,8 @@ impl LogMiddleware {
6768
} else if status.is_client_error() {
6869
if let Some(error) = response.error() {
6970
log::warn!("Client error --> Response sent", {
70-
message: format!("\"{}\"", error.to_string()),
71+
message: format!("{:?}", error),
72+
error_type: error.type_name(),
7173
method: method,
7274
path: path,
7375
status: format!("{} - {}", status as u16, status.canonical_reason()),

0 commit comments

Comments
 (0)