Remove a few unwraps

This commit is contained in:
SkyfallWasTaken 2024-07-01 19:38:52 +01:00
parent 4c09b8e3cd
commit 507e1024d2

View file

@ -30,12 +30,16 @@ pub async fn try_fetch(shop_url: Url) -> Result<ShopItems> {
let doc_html = response.text().await?; let doc_html = response.text().await?;
let doc = Html::parse_document(&doc_html); let doc = Html::parse_document(&doc_html);
let selector = Selector::parse("#__NEXT_DATA__").unwrap(); let selector = Selector::parse("#__NEXT_DATA__").unwrap();
let json: serde_json::Value = let json: serde_json::Value = serde_json::from_str(
serde_json::from_str(&doc.select(&selector).next().unwrap().inner_html())?; &doc.select(&selector)
.next()
.ok_or("no #__NEXT_DATA__ element in document")?
.inner_html(),
)?;
let available_items = serde_json::from_value( let available_items = serde_json::from_value(
json.pointer("/props/pageProps/availableItems") json.pointer("/props/pageProps/availableItems")
.expect("availableItems not found - is the ARCADE_SHOP_URL correct?") .ok_or("availableItems not found - is the ARCADE_SHOP_URL correct?")?
.clone(), .clone(),
)?; )?;