feat(fed): Something about nicer fed errors

This commit is contained in:
nexy7574 2025-08-20 00:56:55 +01:00
commit 4085a90c1f
No known key found for this signature in database

View file

@ -1,4 +1,8 @@
use std::{fmt::Debug, mem}; use std::{
error::Error as _,
fmt::{Debug, Write},
mem,
};
use bytes::Bytes; use bytes::Bytes;
use conduwuit::{ use conduwuit::{
@ -193,9 +197,9 @@ fn handle_error(
) -> Result { ) -> Result {
if e.is_timeout() || e.is_connect() { if e.is_timeout() || e.is_connect() {
e = e.without_url(); e = e.without_url();
debug_warn!(?url, "network error while sending request: {e:?}"); warn!(?url, "network error while sending federation request: {e:?}");
} else if e.is_redirect() { } else if e.is_redirect() {
debug_error!( warn!(
method = ?method, method = ?method,
url = ?url, url = ?url,
final_url = ?e.url(), final_url = ?e.url(),
@ -207,6 +211,14 @@ fn handle_error(
warn!(?url, "failed to send federation request: {e:?}"); warn!(?url, "failed to send federation request: {e:?}");
} }
let mut nice_error = "Request failed".to_owned();
let mut src = e.source();
while let Some(source) = src {
write!(nice_error, ": {source:?}").expect("writing to string should not fail");
src = source.source();
}
warn!(nice_error, "Federation request error");
Err(e.into()) Err(e.into())
} }