From 21f5ab800bb99fc5382605d60c9167a92ca95eca Mon Sep 17 00:00:00 2001 From: ackintosh Date: Wed, 19 Apr 2023 07:59:12 +0900 Subject: [PATCH 1/2] Don't panic while searching gateway --- src/search.rs | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/src/search.rs b/src/search.rs index 9a0625ec..f637fd97 100644 --- a/src/search.rs +++ b/src/search.rs @@ -1,3 +1,5 @@ +use attohttpc::Method; +use attohttpc::RequestBuilder; use std::collections::HashMap; use std::net::{SocketAddrV4, UdpSocket}; use std::str; @@ -37,12 +39,24 @@ pub fn search_gateway(options: SearchOptions) -> Result { let (control_schema_url, control_url) = match get_control_urls(&addr, &root_url) { Ok(o) => o, - Err(..) => continue, + Err(e) => { + debug!( + "Error has occurred while getting control urls. error: {}, addr: {}, root_url: {}", + e, addr, root_url + ); + continue; + } }; let control_schema = match get_schemas(&addr, &control_schema_url) { Ok(o) => o, - Err(..) => continue, + Err(e) => { + debug!( + "Error has occurred while getting schema urls. error: {}, addr: {}, control_schema_url: {}", + e, addr, control_schema_url + ); + continue; + } }; return Ok(Gateway { @@ -57,12 +71,24 @@ pub fn search_gateway(options: SearchOptions) -> Result { fn get_control_urls(addr: &SocketAddrV4, root_url: &str) -> Result<(String, String), SearchError> { let url = format!("http://{}:{}{}", addr.ip(), addr.port(), root_url); - let response = attohttpc::get(&url).send()?; - parsing::parse_control_urls(&response.bytes()?[..]) + + match RequestBuilder::try_new(Method::GET, &url) { + Ok(request_builder) => { + let response = request_builder.send()?; + parsing::parse_control_urls(&response.bytes()?[..]) + } + Err(error) => Err(SearchError::HttpError(error)), + } } fn get_schemas(addr: &SocketAddrV4, control_schema_url: &str) -> Result>, SearchError> { let url = format!("http://{}:{}{}", addr.ip(), addr.port(), control_schema_url); - let response = attohttpc::get(&url).send()?; - parsing::parse_schemas(&response.bytes()?[..]) + + match RequestBuilder::try_new(Method::GET, &url) { + Ok(request_builder) => { + let response = request_builder.send()?; + parsing::parse_schemas(&response.bytes()?[..]) + } + Err(error) => Err(SearchError::HttpError(error)), + } } From 5efa3aadaf3259ff11217b70bf53b095dbcaa4d1 Mon Sep 17 00:00:00 2001 From: ackintosh Date: Wed, 19 Apr 2023 08:23:35 +0900 Subject: [PATCH 2/2] Fix log message --- src/search.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/search.rs b/src/search.rs index f637fd97..fd281b47 100644 --- a/src/search.rs +++ b/src/search.rs @@ -52,7 +52,7 @@ pub fn search_gateway(options: SearchOptions) -> Result { Ok(o) => o, Err(e) => { debug!( - "Error has occurred while getting schema urls. error: {}, addr: {}, control_schema_url: {}", + "Error has occurred while getting schemas. error: {}, addr: {}, control_schema_url: {}", e, addr, control_schema_url ); continue;