From 8d98d1f4bcc344b012ecbfec0b2d9cf1f2f94367 Mon Sep 17 00:00:00 2001 From: red Date: Sun, 1 Nov 2020 13:56:31 +0100 Subject: [PATCH 1/3] made get sessionId silent --- src/lib.rs | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 7964086..d5a8e8c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -56,20 +56,21 @@ impl TransClient { /// /// # Errors /// - /// Panics if any IO error happens + /// If response is impossible to unwrap then it will return an empty session_id async fn get_session_id(&self) -> String { info!("Requesting session id info"); - let response: reqwest::Response = self.rpc_request() + let response: reqwest::Result = self.rpc_request() .json(&RpcRequest::session_get()) .send() - .await - .unwrap(); - let session_id = response.headers() - .get("x-transmission-session-id") - .expect("Unable to get session id") - .to_str() - .unwrap() - .to_owned(); + .await; + let session_id = match response { + Ok(ref resp) => resp.headers() + .get("x-transmission-session-id") + .expect("Unable to get session id") + .to_str() + .unwrap(), + _ => "" + }.to_owned(); info!("Received session id: {}", session_id); session_id } @@ -288,7 +289,9 @@ impl TransClient { let rq: reqwest::RequestBuilder = self.rpc_request() .header("X-Transmission-Session-Id", self.get_session_id().await) .json(&request); - info!("Request body: {:?}", rq.try_clone().unwrap().body_string()?); + info!("Request body: {:?}", rq.try_clone() + .expect("Unable to get the request body") + .body_string()?); let resp: reqwest::Response = rq.send().await?; let rpc_response: RpcResponse = resp.json().await?; info!("Response body: {:#?}", rpc_response); From 989f1cf8d093c41cc906903618c68379bdf658ad Mon Sep 17 00:00:00 2001 From: red Date: Sun, 1 Nov 2020 14:06:22 +0100 Subject: [PATCH 2/3] expected header not to be present --- src/lib.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index d5a8e8c..d6a4196 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -64,11 +64,11 @@ impl TransClient { .send() .await; let session_id = match response { - Ok(ref resp) => resp.headers() - .get("x-transmission-session-id") - .expect("Unable to get session id") - .to_str() - .unwrap(), + Ok(ref resp) => + match resp.headers().get("x-transmission-session-id") { + Some(res) => res.to_str().expect("header value should be a string"), + _ => "" + } _ => "" }.to_owned(); info!("Received session id: {}", session_id); From 07df9ce31053cf2c39adb63e72735628ce255d8e Mon Sep 17 00:00:00 2001 From: red Date: Sun, 1 Nov 2020 14:10:12 +0100 Subject: [PATCH 3/3] bump version --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 9515590..25e44e9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "transmission-rpc" -version = "0.3.0" +version = "0.3.1" authors = ["red "] edition = "2018" repository = "https://github.com/j0rsa/transmission-rpc"