log erroring errors; improve inspection functors.
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
4718387dbe
commit
158de10fe6
3 changed files with 40 additions and 24 deletions
|
@ -1,6 +1,6 @@
|
||||||
use axum::response::{IntoResponse, Response};
|
use axum::response::{IntoResponse, Response};
|
||||||
use bytes::BytesMut;
|
use bytes::BytesMut;
|
||||||
use conduit::Error;
|
use conduit::{error, Error};
|
||||||
use http::StatusCode;
|
use http::StatusCode;
|
||||||
use http_body_util::Full;
|
use http_body_util::Full;
|
||||||
use ruma::api::{client::uiaa::UiaaResponse, OutgoingResponse};
|
use ruma::api::{client::uiaa::UiaaResponse, OutgoingResponse};
|
||||||
|
@ -13,9 +13,12 @@ impl From<Error> for RumaResponse<UiaaResponse> {
|
||||||
|
|
||||||
impl<T: OutgoingResponse> IntoResponse for RumaResponse<T> {
|
impl<T: OutgoingResponse> IntoResponse for RumaResponse<T> {
|
||||||
fn into_response(self) -> Response {
|
fn into_response(self) -> Response {
|
||||||
match self.0.try_into_http_response::<BytesMut>() {
|
self.0
|
||||||
Ok(res) => res.map(BytesMut::freeze).map(Full::new).into_response(),
|
.try_into_http_response::<BytesMut>()
|
||||||
Err(_) => StatusCode::INTERNAL_SERVER_ERROR.into_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(),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -116,18 +116,43 @@ impl Error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Infallible> for Error {
|
#[inline]
|
||||||
fn from(i: Infallible) -> Self { match i {} }
|
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 {
|
impl fmt::Debug for Error {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{self}") }
|
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 {
|
impl axum::response::IntoResponse for Error {
|
||||||
fn into_response(self) -> axum::response::Response {
|
fn into_response(self) -> axum::response::Response {
|
||||||
let response: UiaaResponse = self.into();
|
let response: UiaaResponse = self.into();
|
||||||
response.try_into_http_response::<BytesMut>().map_or_else(
|
response
|
||||||
|
.try_into_http_response::<BytesMut>()
|
||||||
|
.inspect_err(|e| error!(?e))
|
||||||
|
.map_or_else(
|
||||||
|_| StatusCode::INTERNAL_SERVER_ERROR.into_response(),
|
|_| StatusCode::INTERNAL_SERVER_ERROR.into_response(),
|
||||||
|r| r.map(BytesMut::freeze).map(Full::new).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()
|
e.error_kind()
|
||||||
.unwrap_or(&ruma::api::client::error::ErrorKind::Unknown)
|
.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::Line(string) => self.clone().handle(string).await,
|
||||||
ReadlineEvent::Interrupted => continue,
|
ReadlineEvent::Interrupted => continue,
|
||||||
ReadlineEvent::Eof => break,
|
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 {
|
Err(error) => match error {
|
||||||
ReadlineError::Closed => break,
|
ReadlineError::Closed => break,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue