diff options
author | Petr Mrázek <peterix@gmail.com> | 2015-04-05 16:06:15 +0200 |
---|---|---|
committer | Petr Mrázek <peterix@gmail.com> | 2015-04-26 04:09:09 +0200 |
commit | d5c79db12c326bd0175cd2990764948a536abbbb (patch) | |
tree | ae6e419cb4e36d21a65140629cea83a659db3c26 /logic/screenshots/ImgurUpload.cpp | |
parent | f623dc54efc505264ab40746b284289435a2ec26 (diff) | |
download | MultiMC-d5c79db12c326bd0175cd2990764948a536abbbb.tar MultiMC-d5c79db12c326bd0175cd2990764948a536abbbb.tar.gz MultiMC-d5c79db12c326bd0175cd2990764948a536abbbb.tar.lz MultiMC-d5c79db12c326bd0175cd2990764948a536abbbb.tar.xz MultiMC-d5c79db12c326bd0175cd2990764948a536abbbb.zip |
GH-849 Fix failure signals not getting delivered from NetJob properly
Diffstat (limited to 'logic/screenshots/ImgurUpload.cpp')
-rw-r--r-- | logic/screenshots/ImgurUpload.cpp | 57 |
1 files changed, 33 insertions, 24 deletions
diff --git a/logic/screenshots/ImgurUpload.cpp b/logic/screenshots/ImgurUpload.cpp index 053156b9..abb695b3 100644 --- a/logic/screenshots/ImgurUpload.cpp +++ b/logic/screenshots/ImgurUpload.cpp @@ -20,6 +20,7 @@ ImgurUpload::ImgurUpload(ScreenshotPtr shot) : NetAction(), m_shot(shot) void ImgurUpload::start() { + finished = false; m_status = Job_InProgress; QNetworkRequest request(m_url); request.setHeader(QNetworkRequest::UserAgentHeader, "MultiMC/5.0 (Uncached)"); @@ -59,43 +60,51 @@ void ImgurUpload::start() } void ImgurUpload::downloadError(QNetworkReply::NetworkError error) { - qDebug() << m_reply->errorString(); + qCritical() << "ImgurUpload failed with error" << m_reply->errorString() << "Server reply:\n" << m_reply->readAll(); + if(finished) + { + qCritical() << "Double finished ImgurUpload!"; + return; + } m_status = Job_Failed; + finished = true; + m_reply.reset(); + emit failed(m_index_within_job); } void ImgurUpload::downloadFinished() { - if (m_status != Job_Failed) + if(finished) { - QByteArray data = m_reply->readAll(); + qCritical() << "Double finished ImgurUpload!"; + return; + } + QByteArray data = m_reply->readAll(); + m_reply.reset(); + QJsonParseError jsonError; + QJsonDocument doc = QJsonDocument::fromJson(data, &jsonError); + if (jsonError.error != QJsonParseError::NoError) + { + qDebug() << "imgur server did not reply with JSON" << jsonError.errorString(); + finished = true; m_reply.reset(); - QJsonParseError jsonError; - QJsonDocument doc = QJsonDocument::fromJson(data, &jsonError); - if (jsonError.error != QJsonParseError::NoError) - { - qDebug() << jsonError.errorString(); - emit failed(m_index_within_job); - return; - } - auto object = doc.object(); - if (!object.value("success").toBool()) - { - qDebug() << doc.toJson(); - emit failed(m_index_within_job); - return; - } - m_shot->m_imgurId = object.value("data").toObject().value("id").toString(); - m_shot->m_url = object.value("data").toObject().value("link").toString(); - m_status = Job_Finished; - emit succeeded(m_index_within_job); + emit failed(m_index_within_job); return; } - else + auto object = doc.object(); + if (!object.value("success").toBool()) { - qDebug() << m_reply->readAll(); + qDebug() << "Screenshot upload not successful:" << doc.toJson(); + finished = true; m_reply.reset(); emit failed(m_index_within_job); return; } + m_shot->m_imgurId = object.value("data").toObject().value("id").toString(); + m_shot->m_url = object.value("data").toObject().value("link").toString(); + m_status = Job_Finished; + finished = true; + emit succeeded(m_index_within_job); + return; } void ImgurUpload::downloadProgress(qint64 bytesReceived, qint64 bytesTotal) { |