commit 201d6c89e5faf95efaecd7b30fa3de3711e88ce8
parent da6683780ac7aa5580ead9703a3346fbd224fea0
Author: Strange <StrangeGuy6228@protonmail.com>
Date: Tue, 12 Dec 2023 10:04:40 +0530
updated login func to not panic main thread when connection error, instead display the error and exit gracfully. Also removed redundant .clone call in post_msg() func
Diffstat:
1 file changed, 18 insertions(+), 3 deletions(-)
diff --git a/src/main.rs b/src/main.rs
@@ -3,6 +3,7 @@ mod lechatphp;
mod bhc;
use anyhow::{anyhow, Context};
+use std::process;
use log;
use log::LevelFilter;
use log4rs::append::file::FileAppender;
@@ -479,8 +480,22 @@ impl LeChatPHPClient {
return Ok(());
}
if self.chat_type == ClientType::BHC {
- let mut resp_txt = self.client.get(&self.config.url).send().unwrap().text().unwrap();
- let doc = Document::from(resp_txt.as_str());
+ //let mut resp_txt = self.client.get(&self.config.url).send().unwrap().text().unwrap();
+ let mut resp_txt = match self.client.get(&self.config.url).send() {
+ Ok(response) => {
+ match response.text() {
+ Ok(text) => text,
+ Err(err) => {
+ println!("Error: {}\nCheck Your Tor Connection", err);
+ process::exit(0);
+ }
+ }
+ },
+ Err(err) => {
+ println!("Error: {}\nCheck Your Tor Connection", err);
+ process::exit(0);
+ }
+ }; let doc = Document::from(resp_txt.as_str());
if let Some(meta) = doc.find(Name("meta")).next() {
let meta_content = meta.attr("content").context("meta content not found").unwrap().to_owned();
let index_url = META_REFRESH_RGX.captures(&meta_content).unwrap()[1].to_owned();
@@ -1238,7 +1253,7 @@ fn post_msg(client: &Client, post_type_recv: PostType, full_url: &str, session:
let mut should_reset_keepalive_timer = false;
retry_fn(|| -> anyhow::Result<RetryErr> {
let post_type = post_type_recv.clone();
- let resp_text = client.get(url.clone()).send()?.text()?;
+ let resp_text = client.get(url).send()?.text()?;
let doc = Document::from(resp_text.as_str());
let nc = doc.find(Attr("name", "nc")).next().context("nc not found")?;
let nc_value = nc.attr("value").context("nc value not found")?.to_owned();