fix: don't panic on bad server names
This commit is contained in:
		
							parent
							
								
									71500b14b9
								
							
						
					
					
						commit
						0b263208e3
					
				
					 1 changed files with 12 additions and 4 deletions
				
			
		|  | @ -62,14 +62,18 @@ where | ||||||
| 
 | 
 | ||||||
|     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 @@ where | ||||||
|         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 @@ where | ||||||
|                 .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.") | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue