Return an empty channel object if there is no pageInfo item

This usually happens if there are API errors
This commit is contained in:
Daniel Schulte 2020-12-02 22:55:49 +01:00
parent a6fa67bf5a
commit d4ff88ab17
1 changed files with 5 additions and 0 deletions

5
yt.cpp
View File

@ -86,6 +86,11 @@ Channel Channel::add(sqlite3 *db, const std::string &selector, const std::string
const json response = api_request("https://content.googleapis.com/youtube/v3/channels", params); const json response = api_request("https://content.googleapis.com/youtube/v3/channels", params);
// Error responses dont have pageInfo items
if(!response.count("pageInfo")) {
return Channel("", "");
}
const json page_info = response["pageInfo"]; const json page_info = response["pageInfo"];
const bool any_results = page_info["totalResults"] > 0; const bool any_results = page_info["totalResults"] > 0;