Add some context to parse errors

This commit is contained in:
Matteo Settenvini 2022-08-05 22:03:55 +02:00
parent 7495682e41
commit 5e796365f1
Signed by: matteo
GPG key ID: 8576CC1AD97D42DF
2 changed files with 13 additions and 17 deletions

View file

@ -7,7 +7,7 @@ use {
crate::recipe,
crate::scheduling::{Meal, Scheduling},
crate::{constants, helpers},
anyhow::{bail, Result},
anyhow::{anyhow, bail, Result},
chrono::naive::NaiveDate,
futures::future::try_join_all,
icalendar::Event,
@ -93,17 +93,13 @@ async fn get_all_recipes(api_client: &ApiClient) -> Result<HashMap<String, Rc<re
.await?;
let recipes = metadata.iter().map(|rm| async {
let recipe_url = api_client
.base_url()
.join(&format!("apps/cookbook/api/recipes/{id}", id = rm.id))
.unwrap();
let response = api_client
.rest(|client| async {
let r = client
.get(
api_client
.base_url()
.join(&format!("apps/cookbook/api/recipes/{id}", id = rm.id))
.unwrap(),
)
.send()
.await;
let r = client.get(recipe_url.clone()).send().await;
Ok(r?)
})
.await?;
@ -112,7 +108,7 @@ async fn get_all_recipes(api_client: &ApiClient) -> Result<HashMap<String, Rc<re
.json::<recipe::Recipe>()
.await
.map(|r| Rc::new(r))
.map_err(|err| anyhow::anyhow!(err))
.map_err(|err| anyhow!(err).context(format!("while fetching {}", recipe_url)))
});
let recipes = try_join_all(recipes).await?;