mirror of
https://github.com/savoirfairelinux/jami-client-qt.git
synced 2026-01-08 15:06:58 +08:00
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
This commit is contained in:
@@ -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,8 +189,8 @@ 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
|
|||||||
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);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user