fix api/appservice_server events

This commit is contained in:
Charles Hall 2024-07-15 16:25:42 -07:00
parent 162d01f615
commit e49fe04f10
No known key found for this signature in database
GPG key ID: 7B8E0645816E07CF

View file

@ -57,21 +57,19 @@ where
*reqwest_request.timeout_mut() = Some(Duration::from_secs(30)); *reqwest_request.timeout_mut() = Some(Duration::from_secs(30));
let url = reqwest_request.url().clone(); let url = reqwest_request.url().clone();
let mut response = match services() let mut response = services()
.globals .globals
.default_client() .default_client()
.execute(reqwest_request) .execute(reqwest_request)
.await .await
{ .inspect_err(|error| {
Ok(r) => r,
Err(e) => {
warn!( warn!(
"Could not send request to appservice {:?} at {}: {}", %error,
registration.id, destination, e appservice = registration.id,
%destination,
"Could not send request to appservice",
); );
return Err(e.into()); })?;
}
};
// reqwest::Response -> http::Response conversion // reqwest::Response -> http::Response conversion
let status = response.status(); let status = response.status();
@ -85,18 +83,21 @@ where
); );
// TODO: handle timeout // TODO: handle timeout
let body = response.bytes().await.unwrap_or_else(|e| { let body = response.bytes().await.unwrap_or_else(|error| {
warn!("server error: {}", e); warn!(%error, "Server error");
Vec::new().into() Vec::new().into()
}); });
if status != 200 { if status != 200 {
warn!( warn!(
"Appservice returned bad response {} {}\n{}\n{:?}", appservice = %destination,
destination, %status,
status, %url,
url, body = %utils::dbg_truncate_str(
utils::string_from_bytes(&body) String::from_utf8_lossy(&body).as_ref(),
100,
),
"Appservice returned bad response",
); );
} }
@ -106,10 +107,12 @@ where
.expect("reqwest body is valid http body"), .expect("reqwest body is valid http body"),
); );
response.map(Some).map_err(|_| { response.map(Some).map_err(|error| {
warn!( warn!(
"Appservice returned invalid response bytes {}\n{}", %error,
destination, url appservice = %destination,
%url,
"Appservice returned invalid response bytes",
); );
Error::BadServerResponse("Server returned bad response.") Error::BadServerResponse("Server returned bad response.")
}) })