fix std::get error on invalid query

This commit is contained in:
:^) 2024-11-10 19:33:18 +01:00
parent 467f107809
commit 377383d5a0
No known key found for this signature in database
1 changed files with 2 additions and 2 deletions

View File

@ -76,10 +76,10 @@ private:
glz::json_t json{}; glz::json_t json{};
auto ec = glz::read_json(json, response.text); auto ec = glz::read_json(json, response.text);
if (ec != glz::error_code::missing_key) { if (ec != glz::error_code::parse_error && json["queryresult"]["success"].get_boolean()) {
return json["queryresult"]["pods"][1]["subpods"][0]["plaintext"].get<std::string>(); return json["queryresult"]["pods"][1]["subpods"][0]["plaintext"].get<std::string>();
} else { } else {
throw std::invalid_argument("JSON Key not found"); throw std::invalid_argument("WolframAlpha query failed");
} }
} }