Suppress log spam from serverinfo queries

This commit is contained in:
Cameron Gutman 2018-08-05 14:06:42 -07:00
commit 36b42f6e50
2 changed files with 20 additions and 8 deletions

View file

@ -67,6 +67,7 @@ NvHTTP::getServerInfo()
serverInfo = openConnectionToString(m_BaseUrlHttps, serverInfo = openConnectionToString(m_BaseUrlHttps,
"serverinfo", "serverinfo",
nullptr, nullptr,
true,
true); true);
// Throws if the request failed // Throws if the request failed
verifyResponseStatus(serverInfo); verifyResponseStatus(serverInfo);
@ -79,6 +80,7 @@ NvHTTP::getServerInfo()
serverInfo = openConnectionToString(m_BaseUrlHttp, serverInfo = openConnectionToString(m_BaseUrlHttp,
"serverinfo", "serverinfo",
nullptr, nullptr,
true,
true); true);
verifyResponseStatus(serverInfo); verifyResponseStatus(serverInfo);
} }
@ -338,9 +340,10 @@ QString
NvHTTP::openConnectionToString(QUrl baseUrl, NvHTTP::openConnectionToString(QUrl baseUrl,
QString command, QString command,
QString arguments, QString arguments,
bool enableTimeout) bool enableTimeout,
bool suppressLogging)
{ {
QNetworkReply* reply = openConnection(baseUrl, command, arguments, enableTimeout); QNetworkReply* reply = openConnection(baseUrl, command, arguments, enableTimeout, suppressLogging);
QString ret; QString ret;
QTextStream stream(reply); QTextStream stream(reply);
@ -355,7 +358,8 @@ QNetworkReply*
NvHTTP::openConnection(QUrl baseUrl, NvHTTP::openConnection(QUrl baseUrl,
QString command, QString command,
QString arguments, QString arguments,
bool enableTimeout) bool enableTimeout,
bool suppressLogging)
{ {
// Build a URL for the request // Build a URL for the request
QUrl url(baseUrl); QUrl url(baseUrl);
@ -381,13 +385,17 @@ NvHTTP::openConnection(QUrl baseUrl,
{ {
QTimer::singleShot(REQUEST_TIMEOUT_MS, &loop, SLOT(quit())); QTimer::singleShot(REQUEST_TIMEOUT_MS, &loop, SLOT(quit()));
} }
qInfo() << "Executing request:" << url.toString(); if (!suppressLogging) {
qInfo() << "Executing request:" << url.toString();
}
loop.exec(QEventLoop::ExcludeUserInputEvents); loop.exec(QEventLoop::ExcludeUserInputEvents);
// Abort the request if it timed out // Abort the request if it timed out
if (!reply->isFinished()) if (!reply->isFinished())
{ {
qWarning() << "Aborting timed out request for" << url.toString(); if (!suppressLogging) {
qWarning() << "Aborting timed out request for" << url.toString();
}
reply->abort(); reply->abort();
} }
@ -398,7 +406,9 @@ NvHTTP::openConnection(QUrl baseUrl,
// Handle error // Handle error
if (reply->error() != QNetworkReply::NoError) if (reply->error() != QNetworkReply::NoError)
{ {
qWarning() << command << " request failed with error " << reply->error(); if (!suppressLogging) {
qWarning() << command << " request failed with error " << reply->error();
}
GfeHttpResponseException exception(reply->error(), reply->errorString()); GfeHttpResponseException exception(reply->error(), reply->errorString());
delete reply; delete reply;
throw exception; throw exception;

View file

@ -107,7 +107,8 @@ public:
openConnectionToString(QUrl baseUrl, openConnectionToString(QUrl baseUrl,
QString command, QString command,
QString arguments, QString arguments,
bool enableTimeout); bool enableTimeout,
bool suppressLogging = false);
static static
QVector<int> QVector<int>
@ -143,7 +144,8 @@ private:
openConnection(QUrl baseUrl, openConnection(QUrl baseUrl,
QString command, QString command,
QString arguments, QString arguments,
bool enableTimeout); bool enableTimeout,
bool suppressLogging = false);
QString m_Address; QString m_Address;
QNetworkAccessManager m_Nam; QNetworkAccessManager m_Nam;