From d5ba8802830351e19bcf01e42090b81d5fa623d0 Mon Sep 17 00:00:00 2001 From: LostDragonist Date: Thu, 7 Mar 2019 16:55:42 -0600 Subject: Suppress expected network errors during MD5 searches --- src/downloadmanager.cpp | 5 +++-- src/nexusinterface.cpp | 12 +++++++++--- src/nexusinterface.h | 2 ++ 3 files changed, 14 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp index 3563ecdb..25c7e04b 100644 --- a/src/downloadmanager.cpp +++ b/src/downloadmanager.cpp @@ -1373,6 +1373,7 @@ void DownloadManager::setState(DownloadManager::DownloadInfo *info, DownloadMana m_RequestIDs.insert(m_NexusInterface->requestFiles(info->m_FileInfo->gameName, info->m_FileInfo->modID, this, info->m_DownloadID, QString())); } break; case STATE_FETCHINGMODINFO_MD5: { + qDebug(qUtf8Printable(QString("Searching %1 for Md5 of %2").arg(info->m_GamesToQuery[0]).arg(QString(info->m_Hash.toHex())))); m_RequestIDs.insert(m_NexusInterface->requestInfoFromMd5(info->m_GamesToQuery[0], info->m_Hash, this, info->m_DownloadID, QString())); } break; case STATE_READY: { @@ -1796,12 +1797,12 @@ void DownloadManager::nxmRequestFailed(QString gameName, int modID, int fileID, if (info->m_GamesToQuery.count() >= 2) { info->m_GamesToQuery.pop_front(); setState(info, STATE_FETCHINGMODINFO_MD5); - break; + return; } else { info->m_State = STATE_READY; queryInfo(index); emit update(index); - break; + return; } } diff --git a/src/nexusinterface.cpp b/src/nexusinterface.cpp index 33c5983c..6194cd30 100644 --- a/src/nexusinterface.cpp +++ b/src/nexusinterface.cpp @@ -560,6 +560,8 @@ int NexusInterface::requestInfoFromMd5(QString gameName, QByteArray &hash, QObje { NXMRequestInfo requestInfo(hash, NXMRequestInfo::TYPE_FILEINFO_MD5, userData, subModule, game); requestInfo.m_Hash = hash; + requestInfo.m_AllowedErrors[QNetworkReply::NetworkError::ContentNotFoundError].append(404); + requestInfo.m_IgnoreGenericErrorHandler = true; m_RequestQueue.enqueue(requestInfo); connect(this, SIGNAL(nxmFileInfoFromMd5Available(QString, QVariant, QVariant, int)), @@ -721,7 +723,8 @@ void NexusInterface::nextRequest() } connect(info.m_Reply, SIGNAL(finished()), this, SLOT(requestFinished())); - connect(info.m_Reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(requestError(QNetworkReply::NetworkError))); + if (!info.m_IgnoreGenericErrorHandler) + connect(info.m_Reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(requestError(QNetworkReply::NetworkError))); connect(info.m_Timeout, SIGNAL(timeout()), this, SLOT(requestTimeout())); info.m_Timeout->start(); m_ActiveRequest.push_back(info); @@ -737,10 +740,13 @@ void NexusInterface::requestFinished(std::list::iterator iter) { QNetworkReply *reply = iter->m_Reply; - if (reply->error() != QNetworkReply::NoError) { + auto error = reply->error(); + if (error != QNetworkReply::NoError) { int statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); - if (statusCode == 429) { + if (iter->m_AllowedErrors.contains(error) && iter->m_AllowedErrors[error].contains(statusCode)) { + // These errors are allows to silently happen. They should be handled in nxmRequestFailed below. + } else if (statusCode == 429) { if (reply->rawHeader("x-rl-daily-remaining").toInt() || reply->rawHeader("x-rl-hourly-remaining").toInt()) qWarning("You appear to be making requests to the Nexus API too quickly and are being throttled. Please inform the MO2 team."); else diff --git a/src/nexusinterface.h b/src/nexusinterface.h index 6f3c9cd1..ac7f61c5 100644 --- a/src/nexusinterface.h +++ b/src/nexusinterface.h @@ -509,6 +509,8 @@ private: int m_Endorse; int m_Track; QByteArray m_Hash; + QMap> m_AllowedErrors; + bool m_IgnoreGenericErrorHandler; NXMRequestInfo(int modID, Type type, QVariant userData, const QString &subModule, MOBase::IPluginGame const *game); NXMRequestInfo(int modID, QString modVersion, Type type, QVariant userData, const QString &subModule, MOBase::IPluginGame const *game); -- cgit v1.3.1