slightly adjust pusher logging, return if non-successful status instead of continuing
Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
parent
ee07e3e975
commit
46ce15f61f
|
@ -22,7 +22,7 @@ use ruma::{
|
||||||
};
|
};
|
||||||
use tracing::{info, trace, warn};
|
use tracing::{info, trace, warn};
|
||||||
|
|
||||||
use crate::{services, Error, PduEvent, Result};
|
use crate::{debug_info, services, Error, PduEvent, Result};
|
||||||
|
|
||||||
pub(crate) struct Service {
|
pub(crate) struct Service {
|
||||||
pub(crate) db: &'static dyn Data,
|
pub(crate) db: &'static dyn Data,
|
||||||
|
@ -43,18 +43,18 @@ impl Service {
|
||||||
self.db.get_pushkeys(sender)
|
self.db.get_pushkeys(sender)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip(self, destination, request))]
|
#[tracing::instrument(skip(self, dest, request))]
|
||||||
pub(crate) async fn send_request<T>(&self, destination: &str, request: T) -> Result<T::IncomingResponse>
|
pub(crate) async fn send_request<T>(&self, dest: &str, request: T) -> Result<T::IncomingResponse>
|
||||||
where
|
where
|
||||||
T: OutgoingRequest + Debug,
|
T: OutgoingRequest + Debug,
|
||||||
{
|
{
|
||||||
let destination = destination.replace(services().globals.notification_push_path(), "");
|
let dest = dest.replace(services().globals.notification_push_path(), "");
|
||||||
|
|
||||||
let http_request = request
|
let http_request = request
|
||||||
.try_into_http_request::<BytesMut>(&destination, SendAccessToken::IfRequired(""), &[MatrixVersion::V1_0])
|
.try_into_http_request::<BytesMut>(&dest, SendAccessToken::IfRequired(""), &[MatrixVersion::V1_0])
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
warn!("Failed to find destination {}: {}", destination, e);
|
warn!("Failed to find destination {dest} for push gateway: {e}");
|
||||||
Error::BadServerResponse("Invalid destination")
|
Error::BadServerResponse("Invalid push gateway destination")
|
||||||
})?
|
})?
|
||||||
.map(BytesMut::freeze);
|
.map(BytesMut::freeze);
|
||||||
|
|
||||||
|
@ -63,9 +63,7 @@ impl Service {
|
||||||
// TODO: we could keep this very short and let expo backoff do it's thing...
|
// TODO: we could keep this very short and let expo backoff do it's thing...
|
||||||
//*reqwest_request.timeout_mut() = Some(Duration::from_secs(5));
|
//*reqwest_request.timeout_mut() = Some(Duration::from_secs(5));
|
||||||
|
|
||||||
let url = reqwest_request.url().clone();
|
if let Some(url_host) = reqwest_request.url().host_str() {
|
||||||
|
|
||||||
if let Some(url_host) = url.host_str() {
|
|
||||||
trace!("Checking request URL for IP");
|
trace!("Checking request URL for IP");
|
||||||
if let Ok(ip) = IPAddress::parse(url_host) {
|
if let Ok(ip) = IPAddress::parse(url_host) {
|
||||||
if !services().globals.valid_cidr_range(&ip) {
|
if !services().globals.valid_cidr_range(&ip) {
|
||||||
|
@ -105,19 +103,13 @@ impl Service {
|
||||||
.expect("http::response::Builder is usable"),
|
.expect("http::response::Builder is usable"),
|
||||||
);
|
);
|
||||||
|
|
||||||
let body = response.bytes().await.unwrap_or_else(|e| {
|
let body = response.bytes().await?; // TODO: handle timeout
|
||||||
warn!("server error {}", e);
|
|
||||||
Vec::new().into()
|
|
||||||
}); // TODO: handle timeout
|
|
||||||
|
|
||||||
if !status.is_success() {
|
if !status.is_success() {
|
||||||
info!(
|
info!("Push gateway {dest} returned unsuccessful HTTP response ({status})");
|
||||||
"Push gateway returned bad response {} {}\n{}\n{:?}",
|
debug_info!("Push gateway response body: {:?}", crate::utils::string_from_bytes(&body));
|
||||||
destination,
|
|
||||||
status,
|
return Err(Error::BadServerResponse("Push gateway returned unsuccessful response"));
|
||||||
url,
|
|
||||||
crate::utils::string_from_bytes(&body)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let response = T::IncomingResponse::try_from_http_response(
|
let response = T::IncomingResponse::try_from_http_response(
|
||||||
|
@ -125,13 +117,13 @@ 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(|e| {
|
||||||
info!("Push gateway returned invalid response bytes {}\n{}", destination, url);
|
warn!("Push gateway {dest} returned invalid response bytes: {e}");
|
||||||
Error::BadServerResponse("Push gateway returned bad response.")
|
Error::BadServerResponse("Push gateway returned bad/invalid response")
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
warn!("Could not send request to pusher {}: {}", destination, e);
|
warn!("Could not send request to pusher {dest}: {e}");
|
||||||
Err(e.into())
|
Err(e.into())
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue