Improve error messages when updater fails a download (#4594)

Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
This commit is contained in:
nerix 2023-05-02 23:22:04 +02:00 committed by GitHub
parent f39d43faef
commit bcd8028132
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 69 additions and 16 deletions

View file

@ -4,8 +4,10 @@
## Slated for 2.4.3 ## Slated for 2.4.3
- Minor: Improved error messages when the updater fails a download. (#4594)
- Bugfix: Fixed the menu warping on macOS on Qt6. (#4595) - Bugfix: Fixed the menu warping on macOS on Qt6. (#4595)
- Bugfix: Fixed link tooltips not showing unless the thumbnail setting was enabled. (#4597) - Bugfix: Fixed link tooltips not showing unless the thumbnail setting was enabled. (#4597)
- Dev: Added the ability to control the `followRedirect` mode for requests. (#4594)
## 2.4.3 Beta ## 2.4.3 Beta

View file

@ -150,6 +150,24 @@ NetworkRequest NetworkRequest::multiPart(QHttpMultiPart *payload) &&
return std::move(*this); return std::move(*this);
} }
NetworkRequest NetworkRequest::followRedirects(bool on) &&
{
if (on)
{
this->data->request_.setAttribute(
QNetworkRequest::RedirectPolicyAttribute,
QNetworkRequest::NoLessSafeRedirectPolicy);
}
else
{
this->data->request_.setAttribute(
QNetworkRequest::RedirectPolicyAttribute,
QNetworkRequest::ManualRedirectPolicy);
}
return std::move(*this);
}
NetworkRequest NetworkRequest::payload(const QByteArray &payload) && NetworkRequest NetworkRequest::payload(const QByteArray &payload) &&
{ {
this->data->payload_ = payload; this->data->payload_ = payload;

View file

@ -61,6 +61,11 @@ public:
NetworkRequest authorizeTwitchV5(const QString &clientID, NetworkRequest authorizeTwitchV5(const QString &clientID,
const QString &oauthToken = QString()) &&; const QString &oauthToken = QString()) &&;
NetworkRequest multiPart(QHttpMultiPart *payload) &&; NetworkRequest multiPart(QHttpMultiPart *payload) &&;
/**
* This will change `RedirectPolicyAttribute`.
* `QNetworkRequest`'s defaults are used by default (Qt 5: no-follow, Qt 6: follow).
*/
NetworkRequest followRedirects(bool on) &&;
void execute(); void execute();

View file

@ -122,6 +122,18 @@ void Updates::installUpdates()
}); });
}) })
.onSuccess([this](auto result) -> Outcome { .onSuccess([this](auto result) -> Outcome {
if (result.status() != 200)
{
auto *box = new QMessageBox(
QMessageBox::Information, "Chatterino Update",
QStringLiteral("The update couldn't be downloaded "
"(HTTP status %1).")
.arg(result.status()));
box->setAttribute(Qt::WA_DeleteOnClose);
box->exec();
return Failure;
}
QByteArray object = result.getData(); QByteArray object = result.getData();
auto filename = auto filename =
combinePath(getPaths()->miscDirectory, "update.zip"); combinePath(getPaths()->miscDirectory, "update.zip");
@ -171,6 +183,18 @@ void Updates::installUpdates()
box->exec(); box->exec();
}) })
.onSuccess([this](auto result) -> Outcome { .onSuccess([this](auto result) -> Outcome {
if (result.status() != 200)
{
auto *box = new QMessageBox(
QMessageBox::Information, "Chatterino Update",
QStringLiteral("The update couldn't be downloaded "
"(HTTP status %1).")
.arg(result.status()));
box->setAttribute(Qt::WA_DeleteOnClose);
box->exec();
return Failure;
}
QByteArray object = result.getData(); QByteArray object = result.getData();
auto filePath = auto filePath =
combinePath(getPaths()->miscDirectory, "Update.exe"); combinePath(getPaths()->miscDirectory, "Update.exe");
@ -254,52 +278,56 @@ void Updates::checkForUpdates()
NetworkRequest(url) NetworkRequest(url)
.timeout(60000) .timeout(60000)
.onSuccess([this](auto result) -> Outcome { .onSuccess([this](auto result) -> Outcome {
auto object = result.parseJson(); const auto object = result.parseJson();
/// Version available on every platform /// Version available on every platform
QJsonValue version_val = object.value("version"); auto version = object["version"];
if (!version_val.isString()) if (!version.isString())
{ {
this->setStatus_(SearchFailed); this->setStatus_(SearchFailed);
qCDebug(chatterinoUpdate) << "error updating"; qCDebug(chatterinoUpdate)
<< "error checking version - missing 'version'" << object;
return Failure; return Failure;
} }
#if defined Q_OS_WIN || defined Q_OS_MACOS #if defined Q_OS_WIN || defined Q_OS_MACOS
/// Downloads an installer for the new version /// Downloads an installer for the new version
QJsonValue updateExe_val = object.value("updateexe"); auto updateExeUrl = object["updateexe"];
if (!updateExe_val.isString()) if (!updateExeUrl.isString())
{ {
this->setStatus_(SearchFailed); this->setStatus_(SearchFailed);
qCDebug(chatterinoUpdate) << "error updating"; qCDebug(chatterinoUpdate)
<< "error checking version - missing 'updateexe'" << object;
return Failure; return Failure;
} }
this->updateExe_ = updateExe_val.toString(); this->updateExe_ = updateExeUrl.toString();
# ifdef Q_OS_WIN # ifdef Q_OS_WIN
/// Windows portable /// Windows portable
QJsonValue portable_val = object.value("portable_download"); auto portableUrl = object["portable_download"];
if (!portable_val.isString()) if (!portableUrl.isString())
{ {
this->setStatus_(SearchFailed); this->setStatus_(SearchFailed);
qCDebug(chatterinoUpdate) << "error updating"; qCDebug(chatterinoUpdate)
<< "error checking version - missing 'portable_download'"
<< object;
return Failure; return Failure;
} }
this->updatePortable_ = portable_val.toString(); this->updatePortable_ = portableUrl.toString();
# endif # endif
#elif defined Q_OS_LINUX #elif defined Q_OS_LINUX
QJsonValue updateGuide_val = object.value("updateguide"); QJsonValue updateGuide = object.value("updateguide");
if (updateGuide_val.isString()) if (updateGuide.isString())
{ {
this->updateGuideLink_ = updateGuide_val.toString(); this->updateGuideLink_ = updateGuide.toString();
} }
#else #else
return Failure; return Failure;
#endif #endif
/// Current version /// Current version
this->onlineVersion_ = version_val.toString(); this->onlineVersion_ = version.toString();
/// Update available :) /// Update available :)
if (this->currentVersion_ != this->onlineVersion_) if (this->currentVersion_ != this->onlineVersion_)