cleanup scoped types; improve error logging
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
938d1f6e77
commit
1595037427
1 changed files with 11 additions and 17 deletions
|
@ -7,6 +7,7 @@ use std::{
|
||||||
use hickory_resolver::{error::ResolveError, lookup::SrvLookup};
|
use hickory_resolver::{error::ResolveError, lookup::SrvLookup};
|
||||||
use http::{header::AUTHORIZATION, HeaderValue};
|
use http::{header::AUTHORIZATION, HeaderValue};
|
||||||
use ipaddress::IPAddress;
|
use ipaddress::IPAddress;
|
||||||
|
use reqwest::{Client, Method, Request, Response, Url};
|
||||||
use ruma::{
|
use ruma::{
|
||||||
api::{
|
api::{
|
||||||
client::error::Error as RumaError, EndpointError, IncomingResponse, MatrixVersion, OutgoingRequest,
|
client::error::Error as RumaError, EndpointError, IncomingResponse, MatrixVersion, OutgoingRequest,
|
||||||
|
@ -50,9 +51,7 @@ struct ActualDestination {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip_all, name = "send")]
|
#[tracing::instrument(skip_all, name = "send")]
|
||||||
pub(crate) async fn send_request<T>(
|
pub(crate) async fn send_request<T>(client: &Client, destination: &ServerName, req: T) -> Result<T::IncomingResponse>
|
||||||
client: &reqwest::Client, destination: &ServerName, req: T,
|
|
||||||
) -> Result<T::IncomingResponse>
|
|
||||||
where
|
where
|
||||||
T: OutgoingRequest + Debug,
|
T: OutgoingRequest + Debug,
|
||||||
{
|
{
|
||||||
|
@ -71,7 +70,7 @@ where
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
sign_request::<T>(destination, &mut http_request);
|
sign_request::<T>(destination, &mut http_request);
|
||||||
let request = reqwest::Request::try_from(http_request)?;
|
let request = Request::try_from(http_request)?;
|
||||||
let method = request.method().clone();
|
let method = request.method().clone();
|
||||||
let url = request.url().clone();
|
let url = request.url().clone();
|
||||||
validate_url(&url)?;
|
validate_url(&url)?;
|
||||||
|
@ -88,8 +87,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn handle_response<T>(
|
async fn handle_response<T>(
|
||||||
destination: &ServerName, actual: ActualDestination, method: &reqwest::Method, url: &reqwest::Url,
|
destination: &ServerName, actual: ActualDestination, method: &Method, url: &Url, mut response: Response,
|
||||||
mut response: reqwest::Response,
|
|
||||||
) -> Result<T::IncomingResponse>
|
) -> Result<T::IncomingResponse>
|
||||||
where
|
where
|
||||||
T: OutgoingRequest + Debug,
|
T: OutgoingRequest + Debug,
|
||||||
|
@ -141,18 +139,14 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_error<T>(
|
fn handle_error<T>(
|
||||||
_destination: &ServerName, actual: &ActualDestination, method: &reqwest::Method, url: &reqwest::Url,
|
_dest: &ServerName, actual: &ActualDestination, method: &Method, url: &Url, mut e: reqwest::Error,
|
||||||
e: reqwest::Error,
|
|
||||||
) -> Result<T::IncomingResponse>
|
) -> Result<T::IncomingResponse>
|
||||||
where
|
where
|
||||||
T: OutgoingRequest + Debug,
|
T: OutgoingRequest + Debug,
|
||||||
{
|
{
|
||||||
// we do not need to log that servers in a room are dead, this is normal in
|
if e.is_timeout() || e.is_connect() {
|
||||||
// public rooms and just spams the logs.
|
e = e.without_url();
|
||||||
if e.is_timeout() {
|
debug_warn!("{e:?}");
|
||||||
debug_error!("timeout {}: {}", actual.host, e);
|
|
||||||
} else if e.is_connect() {
|
|
||||||
debug_error!("connect {}: {}", actual.host, e);
|
|
||||||
} else if e.is_redirect() {
|
} else if e.is_redirect() {
|
||||||
debug_error!(
|
debug_error!(
|
||||||
method = ?method,
|
method = ?method,
|
||||||
|
@ -163,7 +157,7 @@ where
|
||||||
e,
|
e,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
debug_error!("{}: {}", actual.host, e);
|
debug_error!("{e:?}");
|
||||||
}
|
}
|
||||||
|
|
||||||
Err(e.into())
|
Err(e.into())
|
||||||
|
@ -424,7 +418,7 @@ fn handle_resolve_error(e: &ResolveError) -> Result<()> {
|
||||||
ResolveErrorKind::NoRecordsFound {
|
ResolveErrorKind::NoRecordsFound {
|
||||||
..
|
..
|
||||||
} => {
|
} => {
|
||||||
debug_error!("{e}");
|
debug_warn!("{e}");
|
||||||
Ok(())
|
Ok(())
|
||||||
},
|
},
|
||||||
_ => {
|
_ => {
|
||||||
|
@ -497,7 +491,7 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn validate_url(url: &reqwest::Url) -> Result<()> {
|
fn validate_url(url: &Url) -> Result<()> {
|
||||||
if let Some(url_host) = url.host_str() {
|
if let Some(url_host) = url.host_str() {
|
||||||
if let Ok(ip) = IPAddress::parse(url_host) {
|
if let Ok(ip) = IPAddress::parse(url_host) {
|
||||||
trace!("Checking request URL IP {ip:?}");
|
trace!("Checking request URL IP {ip:?}");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue