diff --git a/src/app/handlers/xdgurl.cpp b/src/app/handlers/xdgurl.cpp index fa37eebf48a2323c7d5a514ed243d42a88bac5ab..5080d17cd15480fc57885d18459cdf5f5e9a8d10 100644 --- a/src/app/handlers/xdgurl.cpp +++ b/src/app/handlers/xdgurl.cpp @@ -77,7 +77,7 @@ void XdgUrl::openDestination() void XdgUrl::networkResourceFinished(qtlibs::NetworkResource *resource) { - if (resource->reply()->error() != QNetworkReply::NoError) { + if (!resource->isFinishedWithNoError()) { QJsonObject result; result["status"] = QString("error_network"); result["message"] = resource->reply()->errorString(); diff --git a/src/libs/qtlibs/networkresource.cpp b/src/libs/qtlibs/networkresource.cpp index 3f3c5652b3efeb89ab9a829b994519f6bfacd19c..1745a1c3c6f946ecc28b363cbe41a6f571600f6e 100644 --- a/src/libs/qtlibs/networkresource.cpp +++ b/src/libs/qtlibs/networkresource.cpp @@ -118,10 +118,18 @@ NetworkResource *NetworkResource::get() return send(async(), networkRequest); } +bool NetworkResource::isFinishedWithNoError() +{ + if (reply()->isFinished() && reply()->error() == QNetworkReply::NoError) { + return true; + } + return false; +} + QByteArray NetworkResource::readData() { QByteArray data; - if (reply()->isFinished()) { + if (isFinishedWithNoError()) { data = reply()->readAll(); } return data; @@ -129,7 +137,7 @@ QByteArray NetworkResource::readData() bool NetworkResource::saveData(const QString &path) { - if (reply()->isFinished()) { + if (isFinishedWithNoError()) { return qtlibs::File(path).writeData(reply()->readAll()); } return false; @@ -144,7 +152,7 @@ void NetworkResource::abort() void NetworkResource::replyFinished() { - if (reply()->error() == QNetworkReply::NoError) { + if (isFinishedWithNoError()) { // Check if redirection // Note: An auto redirection option is available since Qt 5.6 QString newUrl; diff --git a/src/libs/qtlibs/networkresource.h b/src/libs/qtlibs/networkresource.h index 1a4c73bc58ccb8caf4c197bcdced28570c0b4bc1..0a95190cf8b0927bcbfeb2a553796d56e3761a3f 100644 --- a/src/libs/qtlibs/networkresource.h +++ b/src/libs/qtlibs/networkresource.h @@ -44,6 +44,7 @@ public: NetworkResource *head(); NetworkResource *get(); + bool isFinishedWithNoError(); QByteArray readData(); bool saveData(const QString &path);