Mercurial > minori
diff src/core/anime_db.cc @ 176:121c2d5b321f
anime/db: finalize anime db cache
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Fri, 01 Dec 2023 13:12:26 -0500 |
parents | 9b10175be389 |
children | 122fad646f81 |
line wrap: on
line diff
--- a/src/core/anime_db.cc Thu Nov 30 13:52:26 2023 -0500 +++ b/src/core/anime_db.cc Fri Dec 01 13:12:26 2023 -0500 @@ -9,6 +9,9 @@ #include <fstream> +#include <iostream> +#include <exception> + namespace Anime { int Database::GetTotalAnimeAmount() { @@ -271,8 +274,8 @@ anime.SetDuration(JSON::GetNumber(json, "/duration"_json_pointer, 0)); anime.SetPosterUrl(JSON::GetString<std::string>(json, "/poster_url"_json_pointer, "")); - if (json.contains("/list_data") && json.at("/list_data").is_array()) - ParseAnimeUserInfoJSON(json, anime); + if (json.contains("/list_data"_json_pointer) && json.at("/list_data"_json_pointer).is_object()) + ParseAnimeUserInfoJSON(json.at("/list_data"_json_pointer), anime); return true; } @@ -293,9 +296,13 @@ return false; /* When parsing, do NOT throw exceptions */ - nlohmann::json json = json.parse(db_file, nullptr, false); - if (json.is_discarded()) - return false; /* Give up */ + nlohmann::json json; + try { + json = json.parse(db_file); + } catch (std::exception const& ex) { + std::cerr << "[anime/db] Failed to parse JSON! " << ex.what() << std::endl; + return false; + } if (!ParseDatabaseJSON(json)) /* How */ return false;