Add try/catch around json parser

As got:
```
terminate called after throwing an instance of 'nlohmann::detail::parse_error'
terminate called recursively
  what():  [json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal
terminate called recursively
```
This commit is contained in:
Benjamin Loison 2023-01-06 00:31:05 +01:00
parent 5d13bd3c44
commit 01394769fd

View File

@ -310,7 +310,16 @@ json getJson(unsigned short threadId, string url, string directoryPath)
string finalUrl = "https://www.googleapis.com/youtube/v3/" + url + "&key=" + API_KEY; string finalUrl = "https://www.googleapis.com/youtube/v3/" + url + "&key=" + API_KEY;
#endif #endif
string content = getHttps(finalUrl); string content = getHttps(finalUrl);
json data = json::parse(content); json data;
try
{
data = json::parse(content);
}
catch (json::parse_error& ex)
{
PRINT(threadId, "Parse error for " << finalUrl << ", as got: " << content)
exit(1);
}
ostringstream toString; ostringstream toString;
toString << CHANNELS_DIRECTORY << directoryPath << "/" << requestsPerChannel << ".json"; toString << CHANNELS_DIRECTORY << directoryPath << "/" << requestsPerChannel << ".json";