Factor usage of common error type more

This commit is contained in:
Dominik Werder
2021-12-08 13:20:07 +01:00
parent c39af81097
commit 3c64eafd14
56 changed files with 751 additions and 354 deletions

View File

@@ -15,13 +15,16 @@ pub async fn get_channel_config(
let req = hyper::Request::builder()
.method(Method::GET)
.uri(url.as_str())
.body(Body::empty())?;
.body(Body::empty())
.map_err(Error::from_string)?;
let client = hyper::Client::new();
let res = client.request(req).await?;
let res = client.request(req).await.map_err(Error::from_string)?;
if !res.status().is_success() {
return Err(Error::with_msg("http client error"));
}
let buf = hyper::body::to_bytes(res.into_body()).await?;
let buf = hyper::body::to_bytes(res.into_body())
.await
.map_err(Error::from_string)?;
let ret: ChannelConfigResponse = serde_json::from_slice(&buf)?;
Ok(ret)
}