diff --git a/src/async.rs b/src/async.rs index 16d72d5..8a56f2a 100644 --- a/src/async.rs +++ b/src/async.rs @@ -129,13 +129,14 @@ impl AsyncClient { let url = format!("{}{}", self.url, path); let response = self.client.get(url).send().await?; - match response.status().is_success() { - true => Ok(response.json::().await.map_err(Error::Reqwest)?), - false => Err(Error::HttpResponse { + if !response.status().is_success() { + return Err(Error::HttpResponse { status: response.status().as_u16(), message: response.text().await?, - }), + }); } + + response.json::().await.map_err(Error::Reqwest) } /// Make an HTTP GET request to given URL, deserializing to `Option`. @@ -173,17 +174,15 @@ impl AsyncClient { let url = format!("{}{}", self.url, path); let response = self.client.get(url).send().await?; - match response.status().is_success() { - true => { - let hex_str = response.text().await?; - let hex_vec = Vec::from_hex(&hex_str)?; - Ok(deserialize(&hex_vec)?) - } - false => Err(Error::HttpResponse { + if !response.status().is_success() { + return Err(Error::HttpResponse { status: response.status().as_u16(), message: response.text().await?, - }), + }); } + + let hex_str = response.text().await?; + Ok(deserialize(&Vec::from_hex(&hex_str)?)?) } /// Make an HTTP GET request to given URL, deserializing to `Option`. @@ -215,13 +214,14 @@ impl AsyncClient { let url = format!("{}{}", self.url, path); let response = self.client.get(url).send().await?; - match response.status().is_success() { - true => Ok(response.text().await?), - false => Err(Error::HttpResponse { + if !response.status().is_success() { + return Err(Error::HttpResponse { status: response.status().as_u16(), message: response.text().await?, - }), + }); } + + Ok(response.text().await?) } /// Make an HTTP GET request to given URL, deserializing to `Option`. @@ -257,13 +257,14 @@ impl AsyncClient { let response = self.client.post(url).body(body).send().await?; - match response.status().is_success() { - true => Ok(()), - false => Err(Error::HttpResponse { + if !response.status().is_success() { + return Err(Error::HttpResponse { status: response.status().as_u16(), message: response.text().await?, - }), + }); } + + Ok(()) } /// Get a [`Transaction`] option given its [`Txid`]