mirror of
https://git.jami.net/savoirfairelinux/jami-client-qt.git
synced 2025-03-28 14:56:19 +01: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:
parent
0087f1b8a8
commit
c19af7f97f
1 changed files with 7 additions and 3 deletions
|
@ -36,6 +36,8 @@ translateErrorCode(QNetworkReply::NetworkError error)
|
|||
static auto inRange = [](int value, int min, int max) -> bool {
|
||||
return (value >= min && value <= max);
|
||||
};
|
||||
if (error == QNetworkReply::OperationCanceledError)
|
||||
return NetworkManager::CANCELED;
|
||||
if (inRange(error, 1, 199))
|
||||
return NetworkManager::NETWORK_ERROR;
|
||||
if (inRange(error, 201, 201))
|
||||
|
@ -187,8 +189,8 @@ NetworkManager::downloadFile(const QUrl& url,
|
|||
[this, uuid, reply](QNetworkReply::NetworkError error) {
|
||||
reply->disconnect();
|
||||
resetDownload(uuid);
|
||||
qWarning() << Q_FUNC_INFO
|
||||
<< QMetaEnum::fromType<QNetworkReply::NetworkError>().valueToKey(error);
|
||||
qDebug() << Q_FUNC_INFO
|
||||
<< QMetaEnum::fromType<QNetworkReply::NetworkError>().valueToKey(error);
|
||||
Q_EMIT errorOccurred(translateErrorCode(error));
|
||||
});
|
||||
|
||||
|
@ -215,7 +217,9 @@ void
|
|||
NetworkManager::cancelDownload(int replyId)
|
||||
{
|
||||
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();
|
||||
resetDownload(replyId);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue