Skip to content
Snippets Groups Projects
Verified Commit 66e03e04 authored by Tobias Triffterer's avatar Tobias Triffterer :house_with_garden:
Browse files

Add Method to Parse Error Commands

This is a parsing method like the others, this time for error commands.
parent a4958ec5
No related branches found
No related tags found
No related merge requests found
Pipeline #2981 passed with stage
in 22 seconds
......@@ -162,6 +162,23 @@ Command Command::parseStoreToken(const QJsonObject& input)
);
}
Protocol::Command Protocol::Command::parseError(const QJsonObject& input)
{
if (!input.keys().contains(QStringLiteral("message")) || !input.value(QStringLiteral("message")).isString()) {
logError(QStringLiteral("Error command does not contain message."));
return Command();
}
const QString token = (input.keys().contains(QStringLiteral("token")) && input.value(QStringLiteral("token")).isString())
? input.value(QStringLiteral("token")).toString()
: QString();
return Command(
Action::error,
Arguments{std::make_pair(QStringLiteral("message"), input.value(QStringLiteral("message")).toString())},
token
);
}
QString Command::toString() const
{
if (action == Action::invalid)
......
......@@ -71,6 +71,7 @@ private:
static Command parseAuthenticate(const QJsonObject& input);
static Command parseStoreToken(const QJsonObject& input);
static Command parseError(const QJsonObject& input);
static QString getActionString(const Action action);
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment