Skip to content

Commit

Permalink
fix: properly handle rate limiting in tag loader
Browse files Browse the repository at this point in the history
  • Loading branch information
Bionus committed Mar 2, 2023
1 parent 7f0e06e commit 90cf11f
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/lib/src/tags/tag-api-base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ void TagApiBase::parseInternal()
return;
}

// Detect HTTP 429 usage limit reached
const int statusCode = m_reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
if (statusCode == 429) {
log(QStringLiteral("[%1][%2] Limit reached (%3). New try.").arg(m_site->url(), m_api->getName(), QString::number(statusCode)), Logger::Warning);
load(true);
return;
}

// Try to read the reply
QString source = m_reply->readAll();
if (source.isEmpty()) {
Expand All @@ -71,6 +79,5 @@ void TagApiBase::parseInternal()
}

// Parse source
const int statusCode = m_reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
parse(source, statusCode, m_site);
}

0 comments on commit 90cf11f

Please sign in to comment.