diff --git a/src/api/router/response.rs b/src/api/router/response.rs index 9b67f37b..2aaa79fa 100644 --- a/src/api/router/response.rs +++ b/src/api/router/response.rs @@ -1,6 +1,6 @@ use axum::response::{IntoResponse, Response}; use bytes::BytesMut; -use conduit::Error; +use conduit::{error, Error}; use http::StatusCode; use http_body_util::Full; use ruma::api::{client::uiaa::UiaaResponse, OutgoingResponse}; @@ -13,9 +13,12 @@ impl From for RumaResponse { impl IntoResponse for RumaResponse { fn into_response(self) -> Response { - match self.0.try_into_http_response::() { - Ok(res) => res.map(BytesMut::freeze).map(Full::new).into_response(), - Err(_) => StatusCode::INTERNAL_SERVER_ERROR.into_response(), - } + self.0 + .try_into_http_response::() + .inspect_err(|e| error!("response error: {e}")) + .map_or_else( + |_| StatusCode::INTERNAL_SERVER_ERROR.into_response(), + |r| r.map(BytesMut::freeze).map(Full::new).into_response(), + ) } } diff --git a/src/core/error.rs b/src/core/error.rs index 5f4d4798..1959081a 100644 --- a/src/core/error.rs +++ b/src/core/error.rs @@ -116,21 +116,46 @@ impl Error { } } -impl From for Error { - fn from(i: Infallible) -> Self { match i {} } +#[inline] +pub fn log(e: &Error) { + error!(?e); +} + +#[inline] +pub fn debug_log(e: &Error) { + debug_error!(?e); +} + +#[inline] +pub fn into_log(e: Error) { + error!(?e); + drop(e); +} + +#[inline] +pub fn into_debug_log(e: Error) { + debug_error!(?e); + drop(e); } impl fmt::Debug for Error { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{self}") } } +impl From for Error { + fn from(i: Infallible) -> Self { match i {} } +} + impl axum::response::IntoResponse for Error { fn into_response(self) -> axum::response::Response { let response: UiaaResponse = self.into(); - response.try_into_http_response::().map_or_else( - |_| StatusCode::INTERNAL_SERVER_ERROR.into_response(), - |r| r.map(BytesMut::freeze).map(Full::new).into_response(), - ) + response + .try_into_http_response::() + .inspect_err(|e| error!(?e)) + .map_or_else( + |_| StatusCode::INTERNAL_SERVER_ERROR.into_response(), + |r| r.map(BytesMut::freeze).map(Full::new).into_response(), + ) } } @@ -220,15 +245,3 @@ fn ruma_error_kind(e: &ruma::api::client::error::Error) -> &ruma::api::client::e e.error_kind() .unwrap_or(&ruma::api::client::error::ErrorKind::Unknown) } - -#[inline] -pub fn log(e: Error) { - error!("{e}"); - drop(e); -} - -#[inline] -pub fn debug_log(e: Error) { - debug_error!("{e}"); - drop(e); -} diff --git a/src/service/admin/console.rs b/src/service/admin/console.rs index 27a4b6c7..2f66b1d5 100644 --- a/src/service/admin/console.rs +++ b/src/service/admin/console.rs @@ -95,7 +95,7 @@ impl Console { ReadlineEvent::Line(string) => self.clone().handle(string).await, ReadlineEvent::Interrupted => continue, ReadlineEvent::Eof => break, - ReadlineEvent::Quit => services().server.shutdown().unwrap_or_else(error::log), + ReadlineEvent::Quit => services().server.shutdown().unwrap_or_else(error::into_log), }, Err(error) => match error { ReadlineError::Closed => break,