diff --git a/src/request_handler.rs b/src/request_handler.rs index cd7cb87..1ab8f19 100644 --- a/src/request_handler.rs +++ b/src/request_handler.rs @@ -38,11 +38,12 @@ impl RequestHandler { async fn handle_response Deserialize<'de>>(&self, path: String, response: Response) -> Result { let status: StatusCode = response.status(); - if status == StatusCode::OK || status == StatusCode::CREATED { - response.json::().await.map_err(HeliusError::SerdeJson) - } else { - let error_text: String = response.text().await.unwrap_or_default(); - Err(HeliusError::from_response_status(status, path, error_text)) + match status { + StatusCode::OK | StatusCode::CREATED => response.json::().await.map_err(HeliusError::SerdeJson), + _ => { + let error_text = response.text().await.unwrap_or_else(|_| "Failed to read response body".to_string()); + Err(HeliusError::from_response_status(status, path, error_text)) + } } } }