Skip to content
Snippets Groups Projects
Commit c19af7f9 authored by Andreas Traczyk's avatar Andreas Traczyk
Browse files

networkmanager: prevent generic network error when canceling download

To avoid multiple popups when canceling download, we avoid emitting the
`CANCELLED` signal directly, and rely on the QNetworkReply error handler
to emit the `CANCELLED` signal after translating the error triggered by
aborting the download.

Gitlab: #1934
Change-Id: I87bc1404405a9140b52c2c43d2aeb3501e06aec7
parent 0087f1b8
No related branches found
No related tags found
No related merge requests found
...@@ -36,6 +36,8 @@ translateErrorCode(QNetworkReply::NetworkError error) ...@@ -36,6 +36,8 @@ translateErrorCode(QNetworkReply::NetworkError error)
static auto inRange = [](int value, int min, int max) -> bool { static auto inRange = [](int value, int min, int max) -> bool {
return (value >= min && value <= max); return (value >= min && value <= max);
}; };
if (error == QNetworkReply::OperationCanceledError)
return NetworkManager::CANCELED;
if (inRange(error, 1, 199)) if (inRange(error, 1, 199))
return NetworkManager::NETWORK_ERROR; return NetworkManager::NETWORK_ERROR;
if (inRange(error, 201, 201)) if (inRange(error, 201, 201))
...@@ -187,7 +189,7 @@ NetworkManager::downloadFile(const QUrl& url, ...@@ -187,7 +189,7 @@ NetworkManager::downloadFile(const QUrl& url,
[this, uuid, reply](QNetworkReply::NetworkError error) { [this, uuid, reply](QNetworkReply::NetworkError error) {
reply->disconnect(); reply->disconnect();
resetDownload(uuid); resetDownload(uuid);
qWarning() << Q_FUNC_INFO qDebug() << Q_FUNC_INFO
<< QMetaEnum::fromType<QNetworkReply::NetworkError>().valueToKey(error); << QMetaEnum::fromType<QNetworkReply::NetworkError>().valueToKey(error);
Q_EMIT errorOccurred(translateErrorCode(error)); Q_EMIT errorOccurred(translateErrorCode(error));
}); });
...@@ -215,7 +217,9 @@ void ...@@ -215,7 +217,9 @@ void
NetworkManager::cancelDownload(int replyId) NetworkManager::cancelDownload(int replyId)
{ {
if (downloadReplies_.value(replyId) != NULL) { if (downloadReplies_.value(replyId) != NULL) {
Q_EMIT errorOccurred(GetError::CANCELED); // Aborting the download will trigger the emission of a QNetworkReply error
// (`QNetworkReply::OperationCanceledError`), and be caught, translated to our internal
// error `GetError::CANCELED`, and re-emitted.
downloadReplies_[replyId]->abort(); downloadReplies_[replyId]->abort();
resetDownload(replyId); resetDownload(replyId);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment