Check HttpStatusCodeAttribute

This commit is contained in:
Jonas Kvinge 2019-07-30 21:32:20 +02:00
parent 955b906b52
commit 4166ae8db0
2 changed files with 14 additions and 4 deletions

View File

@ -135,6 +135,12 @@ QJsonObject AuddLyricsProvider::ExtractJsonObj(QNetworkReply *reply, const quint
return QJsonObject();
}
if (reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() != 200) {
QString failure_reason = QString("Received HTTP code %1").arg(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt());
Error(id, failure_reason);
return QJsonObject();
}
QByteArray data(reply->readAll());
QJsonParseError error;
@ -209,6 +215,5 @@ QJsonArray AuddLyricsProvider::ExtractResult(QNetworkReply *reply, const quint64
void AuddLyricsProvider::Error(const quint64 id, const QString &error, QVariant debug) {
qLog(Error) << "AudDLyrics:" << error;
if (debug.isValid()) qLog(Debug) << debug;
LyricsSearchResults results;
emit SearchFinished(id, results);
emit SearchFinished(id, LyricsSearchResults());
}

View File

@ -79,6 +79,12 @@ void ChartLyricsProvider::HandleSearchReply(QNetworkReply *reply, const quint64
return;
}
if (reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() != 200) {
QString failure_reason = QString("Received HTTP code %1").arg(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt());
Error(id, failure_reason);
return;
}
QXmlStreamReader reader(reply);
LyricsSearchResults results;
LyricsSearchResult result;
@ -125,6 +131,5 @@ void ChartLyricsProvider::HandleSearchReply(QNetworkReply *reply, const quint64
void ChartLyricsProvider::Error(const quint64 id, const QString &error, QVariant debug) {
qLog(Error) << "ChartLyrics:" << error;
if (debug.isValid()) qLog(Debug) << debug;
LyricsSearchResults results;
emit SearchFinished(id, results);
emit SearchFinished(id, LyricsSearchResults());
}