From b2d22d7ce9d7235cf9ab61268e48102ff06cb727 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Wed, 28 Mar 2018 12:26:31 +0900 Subject: BaseJob: more improvements in logging and errors detection --- jobs/basejob.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'jobs/basejob.cpp') 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() }; } -- cgit v1.2.3