Commit e8b1e7c0 authored by Volker Krause's avatar Volker Krause
Browse files

Handle errors centrally via RESTClient.

parent 48764e54
......@@ -58,8 +58,6 @@ void UserFeedback::Analyzer::DataModel::reload()
beginResetModel();
m_data = QJsonDocument::fromJson(reply->readAll()).array();
endResetModel();
} else {
qDebug() << Q_FUNC_INFO << reply->errorString();
}
});
}
......
......@@ -52,6 +52,7 @@ MainWindow::MainWindow() :
ui->surveyView->setModel(m_surveyModel);
setWindowIcon(QIcon::fromTheme(QStringLiteral("search")));
connect(m_restClient, &RESTClient::errorMessage, this, &MainWindow::logError);
m_productModel->setRESTClient(m_restClient);
m_dataModel->setRESTClient(m_restClient);
m_surveyModel->setRESTClient(m_restClient);
......@@ -82,8 +83,6 @@ MainWindow::MainWindow() :
if (reply->error() == QNetworkReply::NoError) {
logMessage(QString::fromUtf8(reply->readAll()));
m_productModel->reload();
} else {
logError(reply->errorString());
}
});
});
......@@ -99,8 +98,6 @@ MainWindow::MainWindow() :
connect(reply, &QNetworkReply::finished, this, [this, reply]() {
if (reply->error() == QNetworkReply::NoError) {
logMessage(QString::fromUtf8(reply->readAll()));
} else {
logError(reply->errorString());
}
m_productModel->reload();
});
......@@ -121,8 +118,6 @@ MainWindow::MainWindow() :
connect(reply, &QNetworkReply::finished, this, [this, reply]() {
if (reply->error() == QNetworkReply::NoError) {
logMessage(QString::fromUtf8(reply->readAll()));
} else {
logError(reply->errorString());
}
m_surveyModel->reload();
});
......
......@@ -49,8 +49,6 @@ void ProductModel::reload()
auto json = reply->readAll();
m_products = Product::fromJson(json);
endResetModel();
} else {
qWarning() << Q_FUNC_INFO << reply->errorString(); // TODO
}
});
}
......
......@@ -53,7 +53,10 @@ QNetworkReply* RESTClient::get(const QString& command)
const auto authToken = m_serverInfo.userName().toUtf8() + ':' + m_serverInfo.password().toUtf8();
request.setRawHeader("Authorization", "Basic " + authToken.toBase64());
auto reply = m_networkAccessManager->get(request);
// TODO error handling
connect(reply, &QNetworkReply::finished, this, [this, reply]() {
if (reply->error() != QNetworkReply::NoError)
emit errorMessage(reply->errorString());
});
return reply;
}
......@@ -67,7 +70,10 @@ QNetworkReply* RESTClient::post(const QString& command, const QByteArray& data)
request.setRawHeader("Authorization", "Basic " + authToken.toBase64());
request.setHeader(QNetworkRequest::ContentTypeHeader, QStringLiteral("application/json"));
auto reply = m_networkAccessManager->post(request, data);
// TODO error handling
connect(reply, &QNetworkReply::finished, this, [this, reply]() {
if (reply->error() != QNetworkReply::NoError)
emit errorMessage(reply->errorString());
});
return reply;
}
......@@ -80,6 +86,9 @@ QNetworkReply* RESTClient::deleteResource(const QString& command)
const auto authToken = m_serverInfo.userName().toUtf8() + ':' + m_serverInfo.password().toUtf8();
request.setRawHeader("Authorization", "Basic " + authToken.toBase64());
auto reply = m_networkAccessManager->deleteResource(request);
// TODO error handling
connect(reply, &QNetworkReply::finished, this, [this, reply]() {
if (reply->error() != QNetworkReply::NoError)
emit errorMessage(reply->errorString());
});
return reply;
}
......@@ -45,6 +45,7 @@ public:
signals:
void clientConnected();
void errorMessage(const QString &msg);
private:
ServerInfo m_serverInfo;
......
......@@ -57,8 +57,6 @@ void SurveyModel::reload()
const auto data = reply->readAll();
m_surveys = Survey::fromJson(data);
endResetModel();
} else {
qWarning() << reply->errorString();
}
});
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment