Skip to content

Commit

Permalink
v2/{auth,catalog}: make use of error_chain features
Browse files Browse the repository at this point in the history
  • Loading branch information
steveej committed Jan 29, 2020
1 parent aea2077 commit a68a3fc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
5 changes: 1 addition & 4 deletions src/v2/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ impl Client {
match reqwest::Url::parse(&ep) {
Ok(url) => url,
Err(e) => {
return Err(Error::from(format!(
"failed to parse url from string '{}': {}",
ep, e
)));
bail!("failed to parse url from string '{}': {}", ep, e);
}
}
};
Expand Down
25 changes: 10 additions & 15 deletions src/v2/catalog.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::errors::{Error, Result};
use crate::errors::{Result, ResultExt};
use crate::v2;
use async_stream::try_stream;
use futures::stream::Stream;
Expand Down Expand Up @@ -40,19 +40,14 @@ impl v2::Client {
}

async fn fetch_catalog(req: RequestBuilder) -> Result<Catalog> {
match req.send().await {
Ok(r) => {
let status = r.status();
trace!("Got status: {:?}", status);
match status {
StatusCode::OK => r
.json::<Catalog>()
.await
.map_err(|e| format!("get_catalog: failed to fetch the whole body: {}", e)),
_ => Err(format!("get_catalog: wrong HTTP status '{}'", status)),
}
}
Err(err) => Err(format!("{}", err)),
let r = req.send().await?;
let status = r.status();
trace!("Got status: {:?}", status);
match status {
StatusCode::OK => r
.json::<Catalog>()
.await
.chain_err(|| "get_catalog: failed to fetch the whole body"),
_ => bail!("get_catalog: wrong HTTP status '{}'", status),
}
.map_err(Error::from)
}

0 comments on commit a68a3fc

Please sign in to comment.