diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2025-09-14 23:25:33 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2025-09-14 23:25:33 +0800 |
| commit | 8968ee8e536d653a4283e900bfaddc1b456eca75 (patch) | |
| tree | 8c85c3bec92b806054ed0791c4d4c5343b6cb526 | |
| parent | 3d2874a218b0abe736dffa6d9a6b79c103ca5186 (diff) | |
refactor: better error handling
| -rw-r--r-- | src/client/client.rs | 3 | ||||
| -rw-r--r-- | src/client/connector.rs | 5 | ||||
| -rw-r--r-- | src/client/connector/httpconnector.rs | 5 |
3 files changed, 7 insertions, 6 deletions
diff --git a/src/client/client.rs b/src/client/client.rs index cc4cea8..617b688 100644 --- a/src/client/client.rs +++ b/src/client/client.rs @@ -69,7 +69,8 @@ impl<C: Connection> Client<C> { }, env: std::env::vars().collect(), }; - c.connector.init(&c); + // FIXME: handle this and all unwraps + c.connector.init(&c).unwrap(); c } diff --git a/src/client/connector.rs b/src/client/connector.rs index 7b5e1cd..1455eac 100644 --- a/src/client/connector.rs +++ b/src/client/connector.rs @@ -16,7 +16,7 @@ pub trait Connection { // TODO: queue failed ntfy // TODO: impl type of data - fn ntfy(&self, data: String) -> Result<Self::Ok, Self::Err>; + fn ntfy(&self, data: String) -> std::result::Result<(), Self::Err>; fn is_prev(&mut self, str: &Self::Ok) -> bool; @@ -26,7 +26,7 @@ pub trait Connection { _ = Executor::new("network", ["on".to_string()]); } - fn init(&self, c: &Client<Self>) + fn init(&self, c: &Client<Self>) -> std::result::Result<(), Self::Err> where Self: std::marker::Sized, { @@ -35,7 +35,6 @@ pub trait Connection { {c} "#, )) - .unwrap(); } fn reinit(&mut self) { diff --git a/src/client/connector/httpconnector.rs b/src/client/connector/httpconnector.rs index 8f06074..985d9c0 100644 --- a/src/client/connector/httpconnector.rs +++ b/src/client/connector/httpconnector.rs @@ -84,12 +84,13 @@ impl Connection for HTTPConnector { self.handle_response(|| self.client.get(self.pull_url.as_str())) } - fn ntfy(&self, data: String) -> Result<Self::Ok, Self::Err> { + fn ntfy(&self, data: String) -> std::result::Result<(), Self::Err> { self.handle_response(|| { self.client .post(self.ntfy_url.as_str()) .body(data.to_owned()) - }) + })?; + Ok(()) } fn is_prev(&mut self, str: &Self::Ok) -> bool { |
