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 <christian.stenger@qt.io>
Reviewed-by: Andreas Loth <andreas.loth@qt.io>
This commit is contained in:
Jarek Kobus
2024-02-28 16:40:10 +01:00
committed by Christian Stenger
parent 10da1ef3ff
commit d32a5ebb35

View File

@@ -440,24 +440,31 @@ static Group dtoRecipe(const Storage<DtoStorageType<DtoType>> &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<Dto::ErrorDto> error
= Dto::ErrorDto::deserializeExpected(reply->readAll());
if (error) {
if constexpr (std::is_same_v<DtoType, Dto::DashboardInfoDto>) {
// 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;
};