diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2025-09-17 22:10:58 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2025-09-17 22:10:58 +0800 |
| commit | 6942320408b1e7882d9132edd45d781d49a6b570 (patch) | |
| tree | 2ad47b8e5ed8818ee39ffb5b19212e4fcab31b2f | |
| parent | b7bc239c47d419ea5c5b078b89ca11def6c7311b (diff) | |
client(httpconnector): better error handling
| -rw-r--r-- | src/client/connector/httpconnector.rs | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/src/client/connector/httpconnector.rs b/src/client/connector/httpconnector.rs index 9addf66..c636ed9 100644 --- a/src/client/connector/httpconnector.rs +++ b/src/client/connector/httpconnector.rs @@ -6,6 +6,24 @@ use reqwest::{ }; use std::{net::IpAddr, thread::sleep, time::Duration}; +#[derive(Debug)] +pub enum HTTPConnectorError { + Url(url::ParseError), + Reqwest(reqwest::Error), +} + +impl From<url::ParseError> for HTTPConnectorError { + fn from(e: url::ParseError) -> Self { + HTTPConnectorError::Url(e) + } +} + +impl From<reqwest::Error> for HTTPConnectorError { + fn from(e: reqwest::Error) -> Self { + HTTPConnectorError::Reqwest(e) + } +} + pub struct HTTPConnector { network_enforcer: Executor<'static, 'static>, pull_url: Url, @@ -16,7 +34,7 @@ pub struct HTTPConnector { } impl HTTPConnector { - pub fn new(pull_url: &str, ntfy_url: &str, ip_getter_url: &str) -> std::result::Result<Self, url::ParseError> { + pub fn new(pull_url: &str, ntfy_url: &str, ip_getter_url: &str) -> std::result::Result<Self, HTTPConnectorError> { Ok(Self { network_enforcer: Executor::new(&NETWORK_T, ["on"]).unwrap(), // .unwrap() should never panic prev: String::new(), @@ -26,7 +44,13 @@ impl HTTPConnector { Ok(url) => url, Err(_) => Url::parse((pull_url.to_string() + ip_getter_url).as_str())?, }, - client: Client::new(), + client: match Client::builder().build() { + Ok(c) => c, + Err(_) => match Client::builder().danger_accept_invalid_certs(true).build() { + Ok(c) => c, + Err(_) => Client::builder().danger_accept_invalid_certs(true).danger_accept_invalid_hostnames(true).build()?, + }, + }, }) } |
