Commit 3c68d72c authored by Volker Krause's avatar Volker Krause
Browse files

Detect too many request HTTP errors

The gbfs-probe tool hits API limits for some providers now, this will allow
us to throttle requests in that case.
parent f41d088f
Pipeline #78261 passed with stage
in 18 seconds
......@@ -68,9 +68,7 @@ void GBFSJob::discoverFinished(QNetworkReply *reply)
{
reply->deleteLater();
if (reply->error() != QNetworkReply::NoError) {
m_error = NetworkError;
m_errorMsg = reply->errorString();
Q_EMIT finished();
handleNetworkError(reply);
return;
}
......@@ -179,11 +177,7 @@ void GBFSJob::fetchFinished(QNetworkReply *reply, GBFS::FileType type)
--m_pendingJobs;
if (reply->error() != QNetworkReply::NoError) {
m_error = NetworkError;
m_errorMsg = reply->errorString();
if (m_pendingJobs == 0) { // wait for the rest to finish otherwise, to avoid double finished() emission
Q_EMIT finished();
}
handleNetworkError(reply);
return;
}
......@@ -199,6 +193,15 @@ void GBFSJob::fetchFinished(QNetworkReply *reply, GBFS::FileType type)
}
}
void GBFSJob::handleNetworkError(QNetworkReply *reply)
{
m_error = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() == 429 ? TooManyRequestsError : NetworkError;
m_errorMsg = reply->errorString();
if (m_pendingJobs == 0) { // wait for the rest to finish otherwise, to avoid double finished() emission
Q_EMIT finished();
}
}
void GBFSJob::parseData(const QJsonDocument &doc, GBFS::FileType type)
{
switch (type) {
......
......@@ -42,6 +42,7 @@ public:
enum Error {
NoError,
NetworkError,
TooManyRequestsError, ///< API endpoint call limit, try again later
DataError,
};
Error error() const;
......@@ -58,6 +59,7 @@ private:
void parseDiscoverData();
void processFeeds(bool sysInfoOnly);
void fetchFinished(QNetworkReply *reply, GBFS::FileType type);
void handleNetworkError(QNetworkReply *reply);
void parseData(const QJsonDocument &doc, GBFS::FileType type);
void parseSystemInformation(const QJsonDocument &doc);
void parseStationInformation(const QJsonDocument &doc);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment