mikage-emu / saveShop

Let's save the 3DS and Wii U eShop!
90 stars 2 forks source link

Error when fetching rankings for CN (China) #5

Closed Chariblaze closed 1 year ago

Chariblaze commented 1 year ago

cargo run -- fetch-metadata --regions CN --omit-ninja-contents

Processing region CN
Supported languages:
  zh (中文)
Fetching metadata for language "zh" of region CN
Fetching endpoint news
Fetching endpoint telops
Fetching endpoint directories
Fetching endpoint genres
Fetching endpoint publishers
Fetching endpoint publishers/contacts
Fetching endpoint platforms
Fetching endpoint searchcategory
Fetching endpoint languages
Fetching endpoint rankings
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Custom("missing field `rankings`")', src/main.rs:902:80
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

http_log:

--------------------------------------------------
{
  "url": "https://samurai.ctr.shop.nintendo.net/samurai/ws/CN/languages?shop_id=1&lang=zh",
  "response_headers": {
    "server": "nginx",
    "date": "Sun, 19 Mar 2023 23:16:18 GMT",
    "content-type": "application/xml",
    "content-length": "156",
    "connection": "keep-alive",
    "access-control-allow-origin": "*",
    "cache-control": "max-age=120",
    "vary": "Accept-Encoding"
  }
}
--------------------------------------------------
{
  "url": "https://samurai.ctr.shop.nintendo.net/samurai/ws/CN/rankings?shop_id=1&lang=zh",
  "response_headers": {
    "server": "nginx",
    "date": "Sun, 19 Mar 2023 23:16:18 GMT",
    "content-type": "application/xml",
    "content-length": "349",
    "connection": "keep-alive",
    "access-control-allow-origin": "*"
  }
}
--------------------------------------------------

Chinese eShop doesn't have rankings it seems, URL gives an eShop error.

(checking, all 122 other regions do have rankings)

neobrain commented 1 year ago

Thanks for the report!

This patch should fix the issue:

diff --git src/main.rs src/main.rs
index 1bd86d8..6c68e1a 100644
--- src/main.rs
+++ src/main.rs
@@ -899,7 +899,12 @@ async fn fetch_metadata(client: &reqwest::Client, locale: &Locale, args: &Args,
         write!(file, "{}", data)?;

         if matches!(endpoint, EndPoint::Rankings) {
-            let parsed_xml: NodeEshopRankings = quick_xml::de::from_str(&data).unwrap();
+            let parsed_xml: NodeEshopRankings = match quick_xml::de::from_str(&data) {
+                Ok(parsed_xml) => parsed_xml,
+                // NOTE: 3DS eShop returns an error page for region CN
+                Err(err) => { println!("  Failed to parse rankings, skipping ({})", err); continue },
+            };
+
             for ranking in parsed_xml.rankings.ranking {
                 let _: RankingDocument = handle_ranking_content(&client, &ranking.id, &locale).await?;
             }
Chariblaze commented 1 year ago

Thank you, the patch fixes the issue!

neobrain commented 1 year ago

Patch included in latest version. Thanks for testing!