Catch exceptions when parsing invalid json

This commit is contained in:
Duke
2023-03-26 10:08:44 -07:00
parent 7e54360b72
commit b84828604f

View File

@@ -384,16 +384,23 @@ void Executor::run()
emit handleError(response); emit handleError(response);
} }
} }
auto parsed = json::parse( try {
response.toStdString().c_str(), auto parsed = json::parse(
nullptr, response.toStdString().c_str(),
false nullptr,
); false
if (parsed.is_discarded() || parsed.is_null()) { );
if (parsed.is_discarded() || parsed.is_null()) {
emit handleError(response);
} else {
emit responseReady(parsed);
}
} catch (const std::exception& e) {
DEBUG("exception when parsing json: " << e.what() );
emit handleError(response); emit handleError(response);
} else {
emit responseReady(parsed);
} }
} }
void Callback::processRPCCallback(json resp) void Callback::processRPCCallback(json resp)