From d32a5ebb35586b6506fadc4427bdbd8da2f72759 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Wed, 28 Feb 2024 16:40:10 +0100 Subject: [PATCH] Axivion: Suppress the network error logging on unauthorized access This is a valid path to try the unauthorized access first, and when it fails we automatically try the authorized access. So we shouldn't bother the user with an error on a failure on unauthorized access to the dashboard info. Change-Id: Ia27686f804415741da614e36802551f8d8d610ed Reviewed-by: Christian Stenger Reviewed-by: Andreas Loth --- src/plugins/axivion/axivionplugin.cpp | 39 ++++++++++++++++----------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/src/plugins/axivion/axivionplugin.cpp b/src/plugins/axivion/axivionplugin.cpp index 06c0d72aac4..d9ba207de39 100644 --- a/src/plugins/axivion/axivionplugin.cpp +++ b/src/plugins/axivion/axivionplugin.cpp @@ -440,24 +440,31 @@ static Group dtoRecipe(const Storage> &dtoStorage) return DoneResult::Success; } - const auto getError = [&]() -> Error { - if (contentType == s_jsonContentType) { - try { - return DashboardError(reply->url(), statusCode, - reply->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toString(), - Dto::ErrorDto::deserialize(reply->readAll())); - } catch (const Dto::invalid_dto_exception &) { - // ignore + QString errorString; + if (contentType == s_jsonContentType) { + const Utils::expected_str error + = Dto::ErrorDto::deserializeExpected(reply->readAll()); + + if (error) { + if constexpr (std::is_same_v) { + // Suppress logging error on unauthorized dashboard fetch + if (!dtoStorage->credential && error->type == "UnauthenticatedException") + return DoneResult::Error; } + + errorString = Error(DashboardError(reply->url(), statusCode, + reply->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toString(), + *error)).message(); } - if (statusCode != 0) { - return HttpError(reply->url(), statusCode, - reply->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toString(), - QString::fromUtf8(reply->readAll())); // encoding? - } - return NetworkError(reply->url(), error, reply->errorString()); - }; - MessageManager::writeDisrupting(QString("Axivion: %1").arg(getError().message())); + } else if (statusCode != 0) { + errorString = Error(HttpError(reply->url(), statusCode, + reply->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toString(), + QString::fromUtf8(reply->readAll()))).message(); // encoding? + } else { + errorString = Error(NetworkError(reply->url(), error, reply->errorString())).message(); + } + + MessageManager::writeDisrupting(QString("Axivion: %1").arg(errorString)); return DoneResult::Error; };