From b4cb78c6765709372a43c63adc5dc02ee06ed3e4 Mon Sep 17 00:00:00 2001 From: grimhilt Date: Thu, 13 Jul 2023 16:02:20 +0200 Subject: [PATCH] fix issue when getting long body in reqprops --- src/services/req_props.rs | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/services/req_props.rs b/src/services/req_props.rs index 10abf11..28d517f 100644 --- a/src/services/req_props.rs +++ b/src/services/req_props.rs @@ -126,18 +126,21 @@ impl ReqProps { } pub fn send_with_err(&mut self) -> Result { - let res = tokio::runtime::Runtime::new().unwrap().block_on(async { - self.send().await - }).map_err(ApiError::RequestError)?; - - if res.status().is_success() { - let body = tokio::runtime::Runtime::new().unwrap().block_on(async { - res.text().await - }).map_err(ApiError::EmptyError)?; - Ok(body) - } else { - Err(ApiError::IncorrectRequest(res)) - } + tokio::runtime::Runtime::new().unwrap().block_on(async { + match self.send().await { + Err(res) => Err(ApiError::RequestError(res)), + Ok(res) if res.status().is_success() => { + let body = res + .text() + .await + .map_err(|err| ApiError::EmptyError(err))?; + Ok(body) + }, + Ok(res) => { + Err(ApiError::IncorrectRequest(res)) + } + } + }) } pub fn send_req_multiple(&mut self) -> Result, ApiError> {