From 66e03e04553fe2b6ae1e3b53d03d9ccb528221e1 Mon Sep 17 00:00:00 2001 From: Tobias Triffterer <tobias@ep1.ruhr-uni-bochum.de> Date: Fri, 23 Apr 2021 23:53:37 +0200 Subject: [PATCH] Add Method to Parse Error Commands This is a parsing method like the others, this time for error commands. --- src/command.cpp | 17 +++++++++++++++++ src/command.h | 1 + 2 files changed, 18 insertions(+) diff --git a/src/command.cpp b/src/command.cpp index 764e7f2..b001644 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -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) diff --git a/src/command.h b/src/command.h index 9c34b0e..0fd7830 100644 --- a/src/command.h +++ b/src/command.h @@ -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); }; -- GitLab