fix service/pusher events

This commit is contained in:
Charles Hall 2024-07-15 17:43:38 -07:00
parent 9d8e1a1490
commit 52decf0cea
No known key found for this signature in database
GPG key ID: 7B8E0645816E07CF

View file

@ -25,9 +25,9 @@ use ruma::{
serde::Raw, serde::Raw,
uint, RoomId, UInt, UserId, uint, RoomId, UInt, UserId,
}; };
use tracing::{info, warn}; use tracing::warn;
use crate::{services, Error, PduEvent, Result}; use crate::{services, utils, Error, PduEvent, Result};
pub(crate) struct Service { pub(crate) struct Service {
pub(crate) db: &'static dyn Data, pub(crate) db: &'static dyn Data,
@ -78,8 +78,8 @@ impl Service {
SendAccessToken::IfRequired(""), SendAccessToken::IfRequired(""),
&[MatrixVersion::V1_0], &[MatrixVersion::V1_0],
) )
.map_err(|e| { .map_err(|error| {
warn!("Failed to find destination {}: {}", destination, e); warn!(%error, %destination, "Failed to find destination");
Error::BadServerResponse("Invalid destination") Error::BadServerResponse("Invalid destination")
})? })?
.map(BytesMut::freeze); .map(BytesMut::freeze);
@ -105,18 +105,21 @@ impl Service {
); );
// 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 {
info!( warn!(
"Push gateway returned bad response {} {}\n{}\n{:?}", push_gateway = %destination,
destination, %status,
status, %url,
url, body = %utils::dbg_truncate_str(
crate::utils::string_from_bytes(&body) String::from_utf8_lossy(&body).as_ref(),
100,
),
"Push gateway returned bad response",
); );
} }
@ -125,22 +128,25 @@ impl Service {
.body(body) .body(body)
.expect("reqwest body is valid http body"), .expect("reqwest body is valid http body"),
); );
response.map_err(|_| { response.map_err(|error| {
info!( warn!(
"Push gateway returned invalid response bytes {}\n{}", %error,
destination, url appservice = %destination,
%url,
"Push gateway returned invalid response bytes",
); );
Error::BadServerResponse( Error::BadServerResponse(
"Push gateway returned bad response.", "Push gateway returned bad response.",
) )
}) })
} }
Err(e) => { Err(error) => {
warn!( warn!(
"Could not send request to pusher {}: {}", %error,
destination, e %destination,
"Could not send request to push gateway",
); );
Err(e.into()) Err(error.into())
} }
} }
} }