aboutsummaryrefslogtreecommitdiff
path: root/jobs
diff options
context:
space:
mode:
Diffstat (limited to 'jobs')
-rw-r--r--jobs/basejob.cpp24
-rw-r--r--jobs/basejob.h1
2 files changed, 25 insertions, 0 deletions
diff --git a/jobs/basejob.cpp b/jobs/basejob.cpp
index 5198c45c..37345338 100644
--- a/jobs/basejob.cpp
+++ b/jobs/basejob.cpp
@@ -263,7 +263,28 @@ void BaseJob::gotReply()
{
auto json = QJsonDocument::fromJson(d->reply->readAll()).object();
if (!json.isEmpty())
+ {
+ if (error() == TooManyRequestsError)
+ {
+ QString msg = tr("Too many requests");
+ auto retryInterval = json.value("retry_after_ms").toInt(-1);
+ if (retryInterval != -1)
+ msg += tr(", next retry advised after %1 ms")
+ .arg(retryInterval);
+ else // We still have to figure some reasonable interval
+ retryInterval = getNextRetryInterval();
+
+ setStatus(TooManyRequestsError, msg);
+
+ // Shortcut to retry instead of executing the whole finishJob()
+ stop();
+ qCWarning(d->logCat) << this << "will retry in" << retryInterval;
+ d->retryTimer.start(retryInterval);
+ emit retryScheduled(d->retriesTaken, retryInterval);
+ return;
+ }
setStatus(IncorrectRequestError, json.value("error").toString());
+ }
}
finishJob();
@@ -324,6 +345,9 @@ 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
+ return { TooManyRequestsError, tr("Too many requests") };
return { NetworkError, reply->errorString() };
}
}
diff --git a/jobs/basejob.h b/jobs/basejob.h
index fa253d96..ed630a67 100644
--- a/jobs/basejob.h
+++ b/jobs/basejob.h
@@ -62,6 +62,7 @@ namespace QMatrixClient
, NotFoundError
, IncorrectRequestError
, IncorrectResponseError
+ , TooManyRequestsError
, UserDefinedError = 200
};