mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-17 07:41:23 +01:00
drop duplicate warn event
This also gets reported by the "Mark transaction as failed" event.
This commit is contained in:
parent
72860d98db
commit
419af07b97
1 changed files with 58 additions and 77 deletions
|
|
@ -252,87 +252,68 @@ where
|
||||||
tracing::Span::current().record("url", field::display(url));
|
tracing::Span::current().record("url", field::display(url));
|
||||||
|
|
||||||
debug!("Sending request");
|
debug!("Sending request");
|
||||||
let response =
|
let mut response =
|
||||||
services().globals.federation_client().execute(reqwest_request).await;
|
services().globals.federation_client().execute(reqwest_request).await?;
|
||||||
|
|
||||||
match response {
|
// reqwest::Response -> http::Response conversion
|
||||||
Ok(mut response) => {
|
let status = response.status();
|
||||||
// reqwest::Response -> http::Response conversion
|
debug!(status = u16::from(status), "Received response");
|
||||||
let status = response.status();
|
let mut http_response_builder =
|
||||||
debug!(status = u16::from(status), "Received response");
|
http::Response::builder().status(status).version(response.version());
|
||||||
let mut http_response_builder = http::Response::builder()
|
mem::swap(
|
||||||
.status(status)
|
response.headers_mut(),
|
||||||
.version(response.version());
|
http_response_builder
|
||||||
mem::swap(
|
.headers_mut()
|
||||||
response.headers_mut(),
|
.expect("http::response::Builder is usable"),
|
||||||
http_response_builder
|
);
|
||||||
.headers_mut()
|
|
||||||
.expect("http::response::Builder is usable"),
|
debug!("Getting response bytes");
|
||||||
|
// TODO: handle timeout
|
||||||
|
let body = response.bytes().await.unwrap_or_else(|e| {
|
||||||
|
warn!("server error {}", e);
|
||||||
|
Vec::new().into()
|
||||||
|
});
|
||||||
|
debug!("Got response bytes");
|
||||||
|
|
||||||
|
if status != 200 {
|
||||||
|
warn!(
|
||||||
|
status = u16::from(status),
|
||||||
|
response = String::from_utf8_lossy(&body)
|
||||||
|
.lines()
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.join(" "),
|
||||||
|
"Received error over federation",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
let http_response = http_response_builder
|
||||||
|
.body(body)
|
||||||
|
.expect("reqwest body is valid http body");
|
||||||
|
|
||||||
|
if status == 200 {
|
||||||
|
debug!("Parsing response bytes");
|
||||||
|
let response =
|
||||||
|
T::IncomingResponse::try_from_http_response(http_response);
|
||||||
|
if response.is_ok() && write_destination_to_cache {
|
||||||
|
METRICS.record_lookup(
|
||||||
|
FoundKind::FederationDestination,
|
||||||
|
FoundIn::Remote,
|
||||||
);
|
);
|
||||||
|
services().globals.actual_destination_cache.write().await.insert(
|
||||||
debug!("Getting response bytes");
|
OwnedServerName::from(destination),
|
||||||
// TODO: handle timeout
|
(actual_destination, host),
|
||||||
let body = response.bytes().await.unwrap_or_else(|e| {
|
|
||||||
warn!("server error {}", e);
|
|
||||||
Vec::new().into()
|
|
||||||
});
|
|
||||||
debug!("Got response bytes");
|
|
||||||
|
|
||||||
if status != 200 {
|
|
||||||
warn!(
|
|
||||||
status = u16::from(status),
|
|
||||||
response = String::from_utf8_lossy(&body)
|
|
||||||
.lines()
|
|
||||||
.collect::<Vec<_>>()
|
|
||||||
.join(" "),
|
|
||||||
"Received error over federation",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
let http_response = http_response_builder
|
|
||||||
.body(body)
|
|
||||||
.expect("reqwest body is valid http body");
|
|
||||||
|
|
||||||
if status == 200 {
|
|
||||||
debug!("Parsing response bytes");
|
|
||||||
let response =
|
|
||||||
T::IncomingResponse::try_from_http_response(http_response);
|
|
||||||
if response.is_ok() && write_destination_to_cache {
|
|
||||||
METRICS.record_lookup(
|
|
||||||
FoundKind::FederationDestination,
|
|
||||||
FoundIn::Remote,
|
|
||||||
);
|
|
||||||
services()
|
|
||||||
.globals
|
|
||||||
.actual_destination_cache
|
|
||||||
.write()
|
|
||||||
.await
|
|
||||||
.insert(
|
|
||||||
OwnedServerName::from(destination),
|
|
||||||
(actual_destination, host),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
response.map_err(|e| {
|
|
||||||
warn!(error = %e, "Invalid 200 response",);
|
|
||||||
Error::BadServerResponse(
|
|
||||||
"Server returned bad 200 response.",
|
|
||||||
)
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
Err(Error::Federation(
|
|
||||||
destination.to_owned(),
|
|
||||||
RumaError::from_http_response(http_response),
|
|
||||||
))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
warn!(
|
|
||||||
error = %e,
|
|
||||||
"Could not send request",
|
|
||||||
);
|
);
|
||||||
Err(e.into())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
response.map_err(|e| {
|
||||||
|
warn!(error = %e, "Invalid 200 response",);
|
||||||
|
Error::BadServerResponse("Server returned bad 200 response.")
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
Err(Error::Federation(
|
||||||
|
destination.to_owned(),
|
||||||
|
RumaError::from_http_response(http_response),
|
||||||
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue