Handle missing HTTP status code

This commit is contained in:
Jonas Kvinge
2024-12-07 14:02:59 +01:00
parent e1afe03d51
commit fd427dac29
2 changed files with 18 additions and 6 deletions

View File

@@ -158,11 +158,17 @@ ScrobblingAPI20::ReplyResult ScrobblingAPI20::GetJsonObject(QNetworkReply *reply
ReplyResult reply_error_type = ReplyResult::ServerError;
if (reply->error() == QNetworkReply::NoError) {
if (!reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).isValid() || reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() == 200) {
reply_error_type = ReplyResult::Success;
if (reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).isValid()) {
const int http_status_code = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
if (http_status_code == 200) {
reply_error_type = ReplyResult::Success;
}
else {
error_description = QStringLiteral("Received HTTP code %1").arg(http_status_code);
}
}
else {
error_description = QStringLiteral("Received HTTP code %1").arg(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt());
error_description = u"Missing HTTP status code"_s;
}
}
else {