mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 14:55:36 +08:00
Ref T554, parse response of auto publishing
This commit is contained in:
committed by
Mat Sutcliffe
parent
19e421838d
commit
c8eb8ecc2d
@@ -158,5 +158,45 @@ namespace BlackMisc
|
||||
|
||||
return hasData;
|
||||
}
|
||||
|
||||
bool CDatastoreUtility::parseAutoPublishResponse(const QString &jsonResponse, CStatusMessageList &messages)
|
||||
{
|
||||
if (jsonResponse.isEmpty())
|
||||
{
|
||||
messages.push_back(CStatusMessage(getLogCategories(), CStatusMessage::SeverityError, u"Empty JSON data for published models"));
|
||||
return false;
|
||||
}
|
||||
|
||||
const QJsonDocument jsonDoc(QJsonDocument::fromJson(jsonResponse.toUtf8()));
|
||||
|
||||
// array of messages only
|
||||
if (jsonDoc.isArray())
|
||||
{
|
||||
const CStatusMessageList msgs(CStatusMessageList::fromDatabaseJson(jsonDoc.array()));
|
||||
messages.push_back(msgs);
|
||||
return true;
|
||||
}
|
||||
|
||||
// no object -> most likely some fucked up HTML string with the PHP error
|
||||
if (!jsonDoc.isObject())
|
||||
{
|
||||
const QString phpError(CNetworkUtils::removeHtmlPartsFromPhpErrorMessage(jsonResponse));
|
||||
messages.push_back(CStatusMessage(getLogCategories(), CStatusMessage::SeverityError, phpError));
|
||||
return false;
|
||||
}
|
||||
|
||||
QJsonObject json(jsonDoc.object());
|
||||
if (json.contains("msgs"))
|
||||
{
|
||||
const QJsonValue msgJson(json.take("msgs"));
|
||||
const CStatusMessageList msgs(CStatusMessageList::fromDatabaseJson(msgJson.toArray()));
|
||||
if (!msgs.isEmpty())
|
||||
{
|
||||
messages.push_back(msgs);
|
||||
return !messages.hasErrorMessages();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
@@ -56,6 +56,9 @@ namespace BlackMisc
|
||||
Simulation::CAircraftModelList &publishedModels,
|
||||
Simulation::CAircraftModelList &skippedModels,
|
||||
CStatusMessageList &messages, bool &directWrite);
|
||||
|
||||
//! Auto publish response
|
||||
static bool parseAutoPublishResponse(const QString &jsonResponse, CStatusMessageList &messages);
|
||||
};
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user