log erroring errors; improve inspection functors.
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
4718387dbe
commit
158de10fe6
|
@ -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<Error> for RumaResponse<UiaaResponse> {
|
|||
|
||||
impl<T: OutgoingResponse> IntoResponse for RumaResponse<T> {
|
||||
fn into_response(self) -> Response {
|
||||
match self.0.try_into_http_response::<BytesMut>() {
|
||||
Ok(res) => res.map(BytesMut::freeze).map(Full::new).into_response(),
|
||||
Err(_) => StatusCode::INTERNAL_SERVER_ERROR.into_response(),
|
||||
}
|
||||
self.0
|
||||
.try_into_http_response::<BytesMut>()
|
||||
.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(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -116,21 +116,46 @@ impl Error {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<Infallible> 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<Infallible> 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::<BytesMut>().map_or_else(
|
||||
|_| StatusCode::INTERNAL_SERVER_ERROR.into_response(),
|
||||
|r| r.map(BytesMut::freeze).map(Full::new).into_response(),
|
||||
)
|
||||
response
|
||||
.try_into_http_response::<BytesMut>()
|
||||
.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);
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue