Skip to content

Commit

Permalink
Give full error message from server on http error.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kjell Morgenstern authored and KjellMorgenstern committed Dec 20, 2023
1 parent 1df70db commit 9108233
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions src/dialogs/fabuploadprogress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
#include <QDesktopServices>
#include <QSettings>
#include <QMetaEnum>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>

#include "utils/fmessagebox.h"
#include "utils/uploadpair.h"
Expand Down Expand Up @@ -187,9 +190,27 @@ void FabUploadProgress::onError(QNetworkReply::NetworkError code)
// Handle http errors detected
void FabUploadProgress::httpError(QNetworkReply* reply)
{
QString error(reply->errorString() + reply->attribute( QNetworkRequest::HttpStatusCodeAttribute).toString());
DebugDialog::debug(reply->errorString());
FMessageBox::critical(this, tr("Fritzing"), error);
QString statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toString();
QByteArray responseData = reply->readAll();

QJsonDocument jsonDoc = QJsonDocument::fromJson(responseData);
QString jsonErrors;
if (!jsonDoc.isNull() && jsonDoc.isObject()) {
QJsonObject jsonObj = jsonDoc.object();
QJsonArray errorsArray = jsonObj["errors"].toArray();
foreach (const QJsonValue &value, errorsArray) {
jsonErrors += (jsonErrors.isEmpty() ? "" : ", ") + value.toString();
}
}

QString errorMessage = reply->errorString() + " " + statusCode;
if (!jsonErrors.isEmpty()) {
errorMessage += QString(" - %1").arg(jsonErrors);
}

FMessageBox::critical(this, tr("Fritzing"), errorMessage);
DebugDialog::debug(errorMessage);

Q_EMIT closeUploadError();
}

Expand Down

0 comments on commit 9108233

Please sign in to comment.