From d4ff88ab17d2854e97a314203779f12c3ee96c3b Mon Sep 17 00:00:00 2001 From: trilader Date: Wed, 2 Dec 2020 22:55:49 +0100 Subject: [PATCH] Return an empty channel object if there is no pageInfo item This usually happens if there are API errors --- yt.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/yt.cpp b/yt.cpp index 2a2fb85..7f35c30 100644 --- a/yt.cpp +++ b/yt.cpp @@ -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); + // Error responses dont have pageInfo items + if(!response.count("pageInfo")) { + return Channel("", ""); + } + const json page_info = response["pageInfo"]; const bool any_results = page_info["totalResults"] > 0;