aboutsummaryrefslogtreecommitdiff
path: root/jobs/basejob.cpp
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2018-03-28 12:26:31 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2018-03-28 12:26:31 +0900
commitb2d22d7ce9d7235cf9ab61268e48102ff06cb727 (patch)
tree56123b5adf0c1dd75ae55004b36f59344289a4c0 /jobs/basejob.cpp
parentd602de60433da80fc66a7152881d3dfe934eca62 (diff)
downloadlibquotient-b2d22d7ce9d7235cf9ab61268e48102ff06cb727.tar.gz
libquotient-b2d22d7ce9d7235cf9ab61268e48102ff06cb727.zip
BaseJob: more improvements in logging and errors detection
Diffstat (limited to 'jobs/basejob.cpp')
-rw-r--r--jobs/basejob.cpp16
1 files changed, 11 insertions, 5 deletions
diff --git a/jobs/basejob.cpp b/jobs/basejob.cpp
index 37345338..79cfb9e0 100644
--- a/jobs/basejob.cpp
+++ b/jobs/basejob.cpp
@@ -264,7 +264,8 @@ void BaseJob::gotReply()
auto json = QJsonDocument::fromJson(d->reply->readAll()).object();
if (!json.isEmpty())
{
- if (error() == TooManyRequestsError)
+ if (error() == TooManyRequestsError ||
+ json.value("errcode").toString() == "M_LIMIT_EXCEEDED")
{
QString msg = tr("Too many requests");
auto retryInterval = json.value("retry_after_ms").toInt(-1);
@@ -318,10 +319,16 @@ bool checkContentType(const QByteArray& type, const QByteArrayList& patterns)
BaseJob::Status BaseJob::checkReply(QNetworkReply* reply) const
{
- qCDebug(d->logCat) << this << "returned"
+ const auto httpCode =
+ reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
+ qCDebug(d->logCat).nospace().noquote() << this << " returned HTTP code "
+ << httpCode << ": "
<< (reply->error() == QNetworkReply::NoError ?
"Success" : reply->errorString())
- << "from" << reply->url().toDisplayString();
+ << " (URL: " << reply->url().toDisplayString() << ")";
+
+ // Should we check httpCode instead? Maybe even use it in BaseJob::Status?
+ // That would make codes logs slightly more readable.
switch( reply->error() )
{
case QNetworkReply::NoError:
@@ -345,8 +352,7 @@ BaseJob::Status BaseJob::checkReply(QNetworkReply* reply) const
return { NotFoundError, reply->errorString() };
default:
- if (reply->attribute(QNetworkRequest::HttpStatusCodeAttribute)
- .toInt() == 429) // Qt doesn't know about it yet
+ if (httpCode == 429) // Qt doesn't know about it yet
return { TooManyRequestsError, tr("Too many requests") };
return { NetworkError, reply->errorString() };
}