From c6a08169834665ef70d1fa637cbab4fc0a0077a9 Mon Sep 17 00:00:00 2001 From: Leon Lux Date: Sat, 2 Nov 2024 16:30:45 +0100 Subject: [PATCH] use tracings ability to directly log &dyn Error --- axum-extra/src/response/error_response.rs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/axum-extra/src/response/error_response.rs b/axum-extra/src/response/error_response.rs index 334e6d8c7d..f22c2e3e94 100644 --- a/axum-extra/src/response/error_response.rs +++ b/axum-extra/src/response/error_response.rs @@ -1,7 +1,6 @@ use axum_core::response::{IntoResponse, Response}; use http::StatusCode; use std::error::Error; -use std::io::Write; use tracing::error; /// Convenience response to create an error response from a non-IntoResponse error @@ -30,14 +29,8 @@ pub struct InternalServerError(pub T); impl IntoResponse for InternalServerError { fn into_response(self) -> Response { - let mut error: Vec = Vec::new(); - error.push(format!("{}", self.0)); let mut e: &dyn Error = &self.0; - while let Some(new_e) = e.source() { - e = new_e; - error.push(format!(": {e}")) - } - error!("Internal server error: {}", error); + error!(error = e); ( StatusCode::INTERNAL_SERVER_ERROR, "An error occurred while processing your request.",