Throw error when parsed JSON is invalid

Without this error detection, the malformed bootstrap.json
stayed undetected. Hence, the old VATSIM FSD HTTP URL was used.
This commit is contained in:
Lars Toenning
2023-10-04 15:40:35 +02:00
parent 77d7559477
commit d29705a01b
2 changed files with 9 additions and 2 deletions

View File

@@ -71,5 +71,5 @@
} }
] ]
}, },
"wasLoadedFromFile": false, "wasLoadedFromFile": false
} }

View File

@@ -411,7 +411,14 @@ namespace BlackMisc::Json
QJsonObject jsonObjectFromString(const QString &json, bool acceptCacheFormat) QJsonObject jsonObjectFromString(const QString &json, bool acceptCacheFormat)
{ {
if (json.isEmpty()) { return QJsonObject(); } if (json.isEmpty()) { return QJsonObject(); }
const QJsonDocument jsonDoc(QJsonDocument::fromJson(json.toUtf8()));
QJsonParseError error {};
const QJsonDocument jsonDoc(QJsonDocument::fromJson(json.toUtf8(), &error));
if (error.error != QJsonParseError::NoError)
{
throw CJsonException(error.errorString());
}
return acceptCacheFormat ? Json::unwrapCache(jsonDoc.object()) : jsonDoc.object(); return acceptCacheFormat ? Json::unwrapCache(jsonDoc.object()) : jsonDoc.object();
} }