diff options
author | hjk <[email protected]> | 2025-05-23 11:49:13 +0200 |
---|---|---|
committer | hjk <[email protected]> | 2025-05-23 12:44:21 +0000 |
commit | 5dad5bfdd8b0c54cb50cbfbfe9111f22acd7769d (patch) | |
tree | 054801730d8cd674672e277b29f14a543ecfc0d0 | |
parent | d8eb58af2fa3b160c4be009eb4245f093780c2c9 (diff) |
Change-Id: I66c9b270f873af1a871b055a6adb9ca8fd0159c1
Reviewed-by: Christian Stenger <[email protected]>
-rw-r--r-- | src/plugins/axivion/axivionplugin.cpp | 11 | ||||
-rw-r--r-- | src/plugins/axivion/dashboard/error.cpp | 112 | ||||
-rw-r--r-- | src/plugins/axivion/dashboard/error.h | 82 |
3 files changed, 37 insertions, 168 deletions
diff --git a/src/plugins/axivion/axivionplugin.cpp b/src/plugins/axivion/axivionplugin.cpp index 0459071d3d4..ce22c1a5cec 100644 --- a/src/plugins/axivion/axivionplugin.cpp +++ b/src/plugins/axivion/axivionplugin.cpp @@ -653,18 +653,17 @@ static Group dtoRecipe(const Storage<DtoStorageType<DtoType>> &dtoStorage) showFilterException(error->message); return DoneResult::Error; } - errorString = Error(DashboardError(reply->url(), statusCode, - reply->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toString(), - *error)).message(); + errorString = dashboardErrorMessage(reply->url(), statusCode, + reply->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toString(), *error); } else { errorString = error.error(); } } else if (statusCode != 0) { - errorString = Error(HttpError(reply->url(), statusCode, + errorString = httpErrorMessage(reply->url(), statusCode, reply->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toString(), - QString::fromUtf8(reply->readAll()))).message(); // encoding? + QString::fromUtf8(reply->readAll())); // encoding? } else { - errorString = Error(NetworkError(reply->url(), error, reply->errorString())).message(); + errorString = networkErrorMessage(reply->url(), error, reply->errorString()); } showErrorMessage(errorString); diff --git a/src/plugins/axivion/dashboard/error.cpp b/src/plugins/axivion/dashboard/error.cpp index 1ecd7a303af..71c35b74aac 100644 --- a/src/plugins/axivion/dashboard/error.cpp +++ b/src/plugins/axivion/dashboard/error.cpp @@ -7,106 +7,34 @@ #include "dashboard/error.h" -#include <utils/overloaded.h> +namespace Axivion::Internal { -#include <type_traits> -#include <utility> - -namespace Axivion::Internal -{ - -CommunicationError::CommunicationError(QUrl replyUrl) - : replyUrl(std::move(replyUrl)) -{ -} - -GeneralError::GeneralError(QUrl replyUrl, QString message) - : CommunicationError(replyUrl), - message(std::move(message)) -{ -} - -NetworkError::NetworkError(QUrl replyUrl, - QNetworkReply::NetworkError networkError, - QString networkErrorString) - : CommunicationError(std::move(replyUrl)), - networkError(std::move(networkError)), - networkErrorString(std::move(networkErrorString)) -{ -} - -HttpError::HttpError(QUrl replyUrl, int httpStatusCode, QString httpReasonPhrase, QString body) - : CommunicationError(std::move(replyUrl)), - httpStatusCode(httpStatusCode), - httpReasonPhrase(std::move(httpReasonPhrase)), - body(std::move(body)) -{ -} - -DashboardError::DashboardError(QUrl replyUrl, int httpStatusCode, QString httpReasonPhrase, Dto::ErrorDto error) - : CommunicationError(std::move(replyUrl)), - httpStatusCode(httpStatusCode), - httpReasonPhrase(std::move(httpReasonPhrase)), - dashboardVersion(std::move(error.dashboardVersionNumber)), - type(std::move(error.type)), - message(std::move(error.message)) -{ -} - -Error::Error(GeneralError error) : m_error(std::move(error)) -{ -} - -Error::Error(NetworkError error) : m_error(std::move(error)) -{ -} - -Error::Error(HttpError error) : m_error(std::move(error)) -{ -} - -Error::Error(DashboardError error) : m_error(std::move(error)) +QString networkErrorMessage(const QUrl &replyUrl, + QNetworkReply::NetworkError networkError, + const QString &networkErrorString) { + return QStringLiteral("NetworkError (%1) %2: %3") + .arg(replyUrl.toString()).arg(networkError).arg(networkErrorString); } -QString Error::message() const +QString httpErrorMessage(const QUrl &replyUrl, + int httpStatusCode, + const QString &httpReasonPhrase, + const QString &body) { - return std::visit( - Utils::overloaded{ - [](const GeneralError &error) { - return QStringLiteral("GeneralError (%1) %2") - .arg(error.replyUrl.toString(), - error.message); - }, - [](const NetworkError &error) { - return QStringLiteral("NetworkError (%1) %2: %3") - .arg(error.replyUrl.toString(), - QString::number(error.networkError), - error.networkErrorString); - }, - [](const HttpError &error) { - return QStringLiteral("HttpError (%1) %2: %3\n%4") - .arg(error.replyUrl.toString(), - QString::number(error.httpStatusCode), - error.httpReasonPhrase, - error.body); - }, - [](const DashboardError &error) { - return QStringLiteral("DashboardError (%1) [%2 %3] %4: %5") - .arg(error.replyUrl.toString(), - QString::number(error.httpStatusCode), - error.httpReasonPhrase, - error.type, - error.message); - }, - }, this->m_error); + return QStringLiteral("HttpError (%1) %2: %3\n%4") + .arg(replyUrl.toString()).arg(httpStatusCode) + .arg(httpReasonPhrase, body); } -bool Error::isInvalidCredentialsError() +QString dashboardErrorMessage(const QUrl &replyUrl, + int httpStatusCode, + const QString &httpReasonPhrase, + const Dto::ErrorDto &error) { - DashboardError *dashboardError = std::get_if<DashboardError>(&this->m_error); - return dashboardError != nullptr - && dashboardError->type == QLatin1String("InvalidCredentialsException"); + return QStringLiteral("DashboardError (%1) [%2 %3] %4: %5") + .arg(replyUrl.toString()).arg(httpStatusCode) + .arg(httpReasonPhrase, error.type, error.message); } } // namespace Axivion::Internal diff --git a/src/plugins/axivion/dashboard/error.h b/src/plugins/axivion/dashboard/error.h index 2a0f34196fe..09332cda4b9 100644 --- a/src/plugins/axivion/dashboard/error.h +++ b/src/plugins/axivion/dashboard/error.h @@ -11,78 +11,20 @@ #include <QNetworkReply> -#include <variant> +namespace Axivion::Internal { -namespace Axivion::Internal -{ +QString networkErrorMessage(const QUrl &replyUrl, + QNetworkReply::NetworkError networkError, + const QString &networkErrorString); -class CommunicationError -{ -public: - QUrl replyUrl; +QString httpErrorMessage(const QUrl &replyUrl, + int httpStatusCode, + const QString &httpReasonPhrase, + const QString &body); - CommunicationError(QUrl replyUrl); -}; - -class GeneralError : public CommunicationError -{ -public: - QString message; - - GeneralError(QUrl replyUrl, QString message); -}; - -class NetworkError : public CommunicationError -{ -public: - QNetworkReply::NetworkError networkError; - QString networkErrorString; - - NetworkError(QUrl replyUrl, QNetworkReply::NetworkError networkError, QString networkErrorString); -}; - -class HttpError : public CommunicationError -{ -public: - int httpStatusCode; - QString httpReasonPhrase; - QString body; - - HttpError(QUrl replyUrl, int httpStatusCode, QString httpReasonPhrase, QString body); -}; - -class DashboardError : public CommunicationError -{ -public: - int httpStatusCode; - QString httpReasonPhrase; - std::optional<QString> dashboardVersion; - QString type; - QString message; - - DashboardError(QUrl replyUrl, int httpStatusCode, QString httpReasonPhrase, Dto::ErrorDto error); -}; - -class Error -{ -public: - Error(GeneralError error); - - Error(NetworkError error); - - Error(HttpError error); - - Error(DashboardError error); - - QString message() const; - - bool isInvalidCredentialsError(); - -private: - std::variant<GeneralError, - NetworkError, - HttpError, - DashboardError> m_error; -}; +QString dashboardErrorMessage(const QUrl &replyUrl, + int httpStatusCode, + const QString &httpReasonPhrase, + const Dto::ErrorDto &error); } // namespace Axivion::Internal |