mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
fix uncatched exception in json message handling (#164)
This commit is contained in:
parent
d68071cda3
commit
cf2b8b88ee
@ -216,6 +216,9 @@ void JsonClientConnection::handleMessage(const std::string &messageString)
|
|||||||
{
|
{
|
||||||
Json::Reader reader;
|
Json::Reader reader;
|
||||||
Json::Value message;
|
Json::Value message;
|
||||||
|
std::string errors;
|
||||||
|
try
|
||||||
|
{
|
||||||
if (!reader.parse(messageString, message, false))
|
if (!reader.parse(messageString, message, false))
|
||||||
{
|
{
|
||||||
sendErrorReply("Error while parsing json: " + reader.getFormattedErrorMessages());
|
sendErrorReply("Error while parsing json: " + reader.getFormattedErrorMessages());
|
||||||
@ -223,7 +226,6 @@ void JsonClientConnection::handleMessage(const std::string &messageString)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// check basic message
|
// check basic message
|
||||||
std::string errors;
|
|
||||||
if (!checkJson(message, ":schema", errors))
|
if (!checkJson(message, ":schema", errors))
|
||||||
{
|
{
|
||||||
sendErrorReply("Error while validating json: " + errors);
|
sendErrorReply("Error while validating json: " + errors);
|
||||||
@ -266,6 +268,13 @@ void JsonClientConnection::handleMessage(const std::string &messageString)
|
|||||||
else
|
else
|
||||||
handleNotImplemented();
|
handleNotImplemented();
|
||||||
}
|
}
|
||||||
|
catch (std::exception& e)
|
||||||
|
{
|
||||||
|
sendErrorReply("Error while processing incoming json message: " + std::string(e.what()) + " " + errors );
|
||||||
|
Warning(_log, "Error while processing incoming json message: %s (%s)", e.what(), errors.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void JsonClientConnection::forwardJsonMessage(const Json::Value & message)
|
void JsonClientConnection::forwardJsonMessage(const Json::Value & message)
|
||||||
@ -948,7 +957,8 @@ bool JsonClientConnection::checkJson(const Json::Value & message, const QString
|
|||||||
Json::Value schemaJson;
|
Json::Value schemaJson;
|
||||||
if (!jsonReader.parse(reinterpret_cast<const char *>(schemaData.data()), reinterpret_cast<const char *>(schemaData.data()) + schemaData.size(), schemaJson, false))
|
if (!jsonReader.parse(reinterpret_cast<const char *>(schemaData.data()), reinterpret_cast<const char *>(schemaData.data()) + schemaData.size(), schemaJson, false))
|
||||||
{
|
{
|
||||||
throw std::runtime_error("JSONCLIENT ERROR: Schema error: " + jsonReader.getFormattedErrorMessages());
|
errorMessage = "Schema error: " + jsonReader.getFormattedErrorMessages();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// create schema checker
|
// create schema checker
|
||||||
|
Loading…
x
Reference in New Issue
Block a user