Qt 6 - Fix http status response (#3983)

* Fix http status response

* Use QStringLiteral
This commit is contained in:
El Thoro
2025-06-09 02:48:28 +02:00
committed by GitHub
parent aa11f4363c
commit 669dfaadea

View File

@@ -9,6 +9,7 @@
#include "src/widgets/notificationwidget.h" #include "src/widgets/notificationwidget.h"
#include <QBuffer> #include <QBuffer>
#include <QDesktopServices> #include <QDesktopServices>
#include <QJsonArray>
#include <QJsonDocument> #include <QJsonDocument>
#include <QJsonObject> #include <QJsonObject>
#include <QNetworkAccessManager> #include <QNetworkAccessManager>
@@ -31,9 +32,9 @@ void ImgurUploader::handleReply(QNetworkReply* reply)
{ {
spinner()->deleteLater(); spinner()->deleteLater();
m_currentImageName.clear(); m_currentImageName.clear();
QJsonDocument response = QJsonDocument::fromJson(reply->readAll());
QJsonObject json = response.object();
if (reply->error() == QNetworkReply::NoError) { if (reply->error() == QNetworkReply::NoError) {
QJsonDocument response = QJsonDocument::fromJson(reply->readAll());
QJsonObject json = response.object();
QJsonObject data = json[QStringLiteral("data")].toObject(); QJsonObject data = json[QStringLiteral("data")].toObject();
setImageURL(data[QStringLiteral("link")].toString()); setImageURL(data[QStringLiteral("link")].toString());
@@ -54,7 +55,20 @@ void ImgurUploader::handleReply(QNetworkReply* reply)
emit uploadOk(imageURL()); emit uploadOk(imageURL());
} else { } else {
setInfoLabelText(reply->errorString()); QString status;
if (json.contains(QStringLiteral("errors")) &&
json.value(QStringLiteral("errors")).isArray()) {
QJsonArray errorsArray =
json.value(QStringLiteral("errors")).toArray();
if (!errorsArray.isEmpty() && errorsArray.at(0).isObject()) {
QJsonObject errorObj = errorsArray.at(0).toObject();
status = errorObj.value(QStringLiteral("code")).toString() +
" - " +
errorObj.value(QStringLiteral("status")).toString();
}
}
setInfoLabelText(reply->errorString() + "\n" + status);
} }
new QShortcut(Qt::Key_Escape, this, SLOT(close())); new QShortcut(Qt::Key_Escape, this, SLOT(close()));
} }