From 6de8d6cc35138dbdd6d7605da03e3652222ef69f Mon Sep 17 00:00:00 2001 From: Evan <0xIchigo@protonmail.com> Date: Tue, 21 May 2024 14:02:56 -0400 Subject: [PATCH] Handle Empty Response Body --- src/request_handler.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/request_handler.rs b/src/request_handler.rs index 0bcee88..a540f2f 100644 --- a/src/request_handler.rs +++ b/src/request_handler.rs @@ -81,12 +81,16 @@ impl RequestHandler { /// /// # Errors /// Returns an error if deserialization fails or if the response status indicates a failure (e.g., 404 Not Found) - async fn handle_response Deserialize<'de>>(&self, response: Response) -> Result { + async fn handle_response Deserialize<'de> + Default>(&self, response: Response) -> Result { let status: StatusCode = response.status(); let path: String = response.url().path().to_string(); let body_text: String = response.text().await.unwrap_or_default(); if status.is_success() { + if body_text.is_empty() { + return Ok(T::default()); + } + match serde_json::from_str::(&body_text) { Ok(data) => Ok(data), Err(e) => {