Skip to content
Snippets Groups Projects
Unverified Commit 0b263208 authored by Timo Kösters's avatar Timo Kösters
Browse files

fix: don't panic on bad server names

parent 71500b14
No related branches found
No related tags found
No related merge requests found
...@@ -62,14 +62,18 @@ pub async fn send_request<T: OutgoingRequest>( ...@@ -62,14 +62,18 @@ pub async fn send_request<T: OutgoingRequest>(
let mut http_request = request let mut http_request = request
.try_into_http_request(&actual_destination, Some("")) .try_into_http_request(&actual_destination, Some(""))
.unwrap(); .map_err(|e| {
warn!("{}: {}", actual_destination, e);
Error::BadServerResponse("Invalid destination")
})?;
let mut request_map = serde_json::Map::new(); let mut request_map = serde_json::Map::new();
if !http_request.body().is_empty() { if !http_request.body().is_empty() {
request_map.insert( request_map.insert(
"content".to_owned(), "content".to_owned(),
serde_json::from_slice(http_request.body()).unwrap(), serde_json::from_slice(http_request.body())
.expect("body is valid json, we just created it"),
); );
}; };
...@@ -92,7 +96,7 @@ pub async fn send_request<T: OutgoingRequest>( ...@@ -92,7 +96,7 @@ pub async fn send_request<T: OutgoingRequest>(
globals.keypair(), globals.keypair(),
&mut request_json, &mut request_json,
) )
.unwrap(); .expect("our request json is what ruma expects");
let signatures = request_json["signatures"] let signatures = request_json["signatures"]
.as_object() .as_object()
...@@ -145,7 +149,11 @@ pub async fn send_request<T: OutgoingRequest>( ...@@ -145,7 +149,11 @@ pub async fn send_request<T: OutgoingRequest>(
.into_iter() .into_iter()
.collect(); .collect();
let response = T::IncomingResponse::try_from(http_response.body(body).unwrap()); let response = T::IncomingResponse::try_from(
http_response
.body(body)
.expect("reqwest body is valid http body"),
);
response.map_err(|e| { response.map_err(|e| {
warn!("{}", e); warn!("{}", e);
Error::BadServerResponse("Server returned bad response.") Error::BadServerResponse("Server returned bad response.")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment