update test connection to evaluate response (#54)
parent
8216ec0c63
commit
0f54218281
|
@ -85,6 +85,7 @@ HEADERS += \
|
|||
src/components/tagging/tagview.h \
|
||||
src/components/tagging/tagwidget.h \
|
||||
src/db/databaseconnection.h \
|
||||
src/dtos/checkConnection.h \
|
||||
src/exceptions/databaseerr.h \
|
||||
src/exceptions/fileerror.h \
|
||||
src/forms/evidence_filter/evidencefilter.h \
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
#ifndef TESTCONNECTION_H
|
||||
#define TESTCONNECTION_H
|
||||
|
||||
#include <QVariant>
|
||||
|
||||
#include "helpers/jsonhelpers.h"
|
||||
|
||||
namespace dto {
|
||||
class CheckConnection {
|
||||
public:
|
||||
CheckConnection(){}
|
||||
|
||||
bool ok;
|
||||
bool parsedCorrectly;
|
||||
|
||||
static CheckConnection parseJson(QByteArray data) {
|
||||
QJsonParseError err;
|
||||
QJsonDocument doc = QJsonDocument::fromJson(data, &err);
|
||||
CheckConnection cc;
|
||||
|
||||
cc.parsedCorrectly = false;
|
||||
if (err.error == QJsonParseError::NoError) {
|
||||
QJsonValue val = doc["ok"];
|
||||
if (!val.isUndefined()) {
|
||||
cc.parsedCorrectly = true;
|
||||
cc.ok = val.toBool();
|
||||
}
|
||||
}
|
||||
|
||||
return cc;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif // TESTCONNECTION_H
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
#include "appconfig.h"
|
||||
#include "appsettings.h"
|
||||
#include "dtos/checkConnection.h"
|
||||
#include "helpers/http_status.h"
|
||||
#include "helpers/netman.h"
|
||||
#include "helpers/stopreply.h"
|
||||
|
@ -272,12 +273,20 @@ void Settings::onTestRequestComplete() {
|
|||
currentTestReply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(&ok);
|
||||
|
||||
if (ok) {
|
||||
dto::CheckConnection connectionCheckResp;
|
||||
|
||||
switch (statusCode) {
|
||||
case HttpStatus::StatusOK:
|
||||
connStatusLabel->setText("Connected");
|
||||
connectionCheckResp = dto::CheckConnection::parseJson(currentTestReply->readAll());
|
||||
if (connectionCheckResp.parsedCorrectly && connectionCheckResp.ok) {
|
||||
connStatusLabel->setText("Connected");
|
||||
}
|
||||
else {
|
||||
connStatusLabel->setText("Unable to connect: Wrong or outdated server");
|
||||
}
|
||||
break;
|
||||
case HttpStatus::StatusUnauthorized:
|
||||
connStatusLabel->setText("Could not connect: Unauthorized (check api key and secret)");
|
||||
connStatusLabel->setText("Could not connect: Unauthorized (check access key and secret)");
|
||||
break;
|
||||
case HttpStatus::StatusNotFound:
|
||||
connStatusLabel->setText("Could not connect: Not Found (check URL)");
|
||||
|
|
|
@ -43,6 +43,7 @@ class NetMan : public QObject {
|
|||
|
||||
void operationListUpdated(bool success,
|
||||
std::vector<dto::Operation> operations = std::vector<dto::Operation>());
|
||||
void testConnectionComplete(bool connected, int statusCode);
|
||||
|
||||
private:
|
||||
QNetworkAccessManager *nam;
|
||||
|
@ -183,7 +184,7 @@ class NetMan : public QObject {
|
|||
}
|
||||
|
||||
QNetworkReply *testConnection(QString host, QString apiKey, QString secretKey) {
|
||||
return makeJsonRequest(METHOD_GET, "/api/operations", NO_BODY, host, apiKey, secretKey);
|
||||
return makeJsonRequest(METHOD_GET, "/api/checkconnection", NO_BODY, host, apiKey, secretKey);
|
||||
}
|
||||
|
||||
QNetworkReply *getAllOperations() { return makeJsonRequest(METHOD_GET, "/api/operations"); }
|
||||
|
|
Loading…
Reference in New Issue