From 4225c76df33486cc072498453dc7497764fb268e Mon Sep 17 00:00:00 2001 From: Carlos Rueda Date: Tue, 6 Feb 2024 11:24:24 -0800 Subject: [PATCH] properly handle response --- Cargo.toml | 2 +- ChangeLog.md | 4 ++++ src/trackdb_client.rs | 26 ++++++++++++++++++++------ 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d1b6d7e..1aa2878 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "odss2dash" -version = "2.1.2" +version = "2.2.0" authors = [ "Carlos A. Rueda ", ] diff --git a/ChangeLog.md b/ChangeLog.md index 8ee3056..d5d6706 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,5 +1,9 @@ 2024-02 +2.2.0 + +- trackdb_client: properly handle response, e.g., when an invalid platform ID is queried. + 2.1.2 - some lib updates diff --git a/src/trackdb_client.rs b/src/trackdb_client.rs index e51b5f3..605a68f 100644 --- a/src/trackdb_client.rs +++ b/src/trackdb_client.rs @@ -51,9 +51,16 @@ pub fn get_platforms() -> Vec { match request.send() { Ok(res) => { if res.is_success() { - let platforms_res = res.json::>().unwrap(); - log::debug!("odss platforms_res = {:?}", platforms_res); - platforms_res + match res.json::>() { + Ok(platforms_res) => { + log::debug!("odss platforms_res = {:?}", platforms_res); + platforms_res + } + Err(e) => { + log::error!("could not parse response: {}", e); + vec![] + } + } } else { log::error!( "GET {endpoint}: response: status={}, body={}", @@ -79,9 +86,16 @@ pub fn get_platform(platform_id: &str) -> Option { match request.send() { Ok(res) => { if res.is_success() { - let platforms_res = res.json::().unwrap(); - log::debug!("odss platform_res = {:?}", platforms_res); - Some(platforms_res) + match res.json::() { + Ok(platform_res) => { + log::debug!("odss platform_res = {:?}", platform_res); + Some(platform_res) + } + Err(e) => { + log::error!("could not parse response: {}", e); + None + } + } } else { log::error!( "GET {endpoint} response: status={}, body={}",