Skip to content

Commit

Permalink
use tracings ability to directly log &dyn Error
Browse files Browse the repository at this point in the history
  • Loading branch information
Lachstec committed Nov 2, 2024
1 parent b1aa73c commit c6a0816
Showing 1 changed file with 1 addition and 8 deletions.
9 changes: 1 addition & 8 deletions axum-extra/src/response/error_response.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -30,14 +29,8 @@ pub struct InternalServerError<T>(pub T);

impl<T: Error> IntoResponse for InternalServerError<T> {
fn into_response(self) -> Response {
let mut error: Vec<String> = 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.",
Expand Down

0 comments on commit c6a0816

Please sign in to comment.