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 dab4c8ff69
commit 292dd8919e
Signed by: Benjamin_Loison
SSH Key Fingerprint: SHA256:BtnEgYTlHdOg1u+RmYcDE0mnfz1rhv5dSbQ2gyxW8B8

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";