slight misc error.rs changes

Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
strawberry 2024-04-23 23:44:56 -04:00 committed by June
parent f0dd3930fa
commit 0734b52a8a
2 changed files with 11 additions and 19 deletions

View file

@ -5,7 +5,7 @@ use ruma::{
RoomId, RoomVersionId, ServerName,
};
use tokio::sync::RwLock;
use tracing::{debug, error, info, warn};
use tracing::{debug, info, warn};
use tracing_subscriber::EnvFilter;
use crate::{api::server_server::parse_incoming_pdu, services, utils::HtmlEscape, Error, PduEvent, Result};
@ -245,7 +245,7 @@ pub(crate) async fn get_room_state(_body: Vec<&str>, room_id: Box<RoomId>) -> Re
}
let json_text = serde_json::to_string_pretty(&room_state).map_err(|e| {
error!("Failed converting room state vector in our database to pretty JSON: {e}");
warn!("Failed converting room state vector in our database to pretty JSON: {e}");
Error::bad_database(
"Failed to convert room state events to pretty JSON, possible invalid room state events in our database",
)
@ -297,7 +297,7 @@ pub(crate) async fn ping(_body: Vec<&str>, server: Box<ServerName>) -> Result<Ro
)))
},
Err(e) => {
error!("Failed sending federation request to specified server from ping debug command: {e}");
warn!("Failed sending federation request to specified server from ping debug command: {e}");
Ok(RoomMessageEventContent::text_plain(format!(
"Failed sending federation request to specified server:\n\n{e}",
)))

View file

@ -1,4 +1,4 @@
use std::convert::Infallible;
use std::{convert::Infallible, fmt};
use http::StatusCode;
use ruma::{
@ -9,13 +9,13 @@ use ruma::{
OwnedServerName,
};
use thiserror::Error;
use tracing::{debug, error};
use tracing::error;
use ErrorKind::{
Forbidden, GuestAccessForbidden, LimitExceeded, MissingToken, NotFound, ThreepidAuthFailed, ThreepidDenied,
TooLarge, Unauthorized, Unknown, UnknownToken, Unrecognized, UserDeactivated, WrongRoomKeysVersion,
};
use crate::RumaResponse;
use crate::{debug_info, RumaResponse};
pub(crate) type Result<T, E = Error> = std::result::Result<T, E>;
@ -92,9 +92,7 @@ impl Error {
error!("BadConfig: {}", message);
Self::BadConfig(message.to_owned())
}
}
impl Error {
pub(crate) fn to_response(&self) -> RumaResponse<UiaaResponse> {
if let Self::Uiaa(uiaainfo) = self {
return RumaResponse(UiaaResponse::AuthResponse(uiaainfo.clone()));
@ -103,7 +101,7 @@ impl Error {
if let Self::Federation(origin, error) = self {
let mut error = error.clone();
error.body = ErrorBody::Standard {
kind: error.error_kind().unwrap_or(&Unknown).clone(),
kind: error.error_kind().unwrap_or_else(|| &Unknown).clone(),
message: format!("Answer from {origin}: {error}"),
};
return RumaResponse(UiaaResponse::MatrixError(error));
@ -141,7 +139,7 @@ impl Error {
_ => (Unknown, StatusCode::INTERNAL_SERVER_ERROR),
};
debug!("Returning an error: {status_code}: {message}");
debug_info!("Returning an error: {status_code}: {message}");
RumaResponse(UiaaResponse::MatrixError(RumaError {
body: ErrorBody::Standard {
kind,
@ -154,7 +152,7 @@ impl Error {
/// Returns the Matrix error code / error kind
pub(crate) fn error_code(&self) -> ErrorKind {
if let Self::Federation(_, error) = self {
return error.error_kind().unwrap_or(&Unknown).clone();
return error.error_kind().unwrap_or_else(|| &Unknown).clone();
}
match self {
@ -179,12 +177,6 @@ impl Error {
Self::Io {
..
} => db_error,
Self::BadConfig {
..
} => db_error,
Self::BadDatabase {
..
} => db_error,
_ => self.to_string(),
}
}
@ -198,6 +190,6 @@ impl axum::response::IntoResponse for Error {
fn into_response(self) -> axum::response::Response { self.to_response().into_response() }
}
impl std::fmt::Debug for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self) }
impl fmt::Debug for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self) }
}