Handle the case login tokens are destroyed

This commit is contained in:
Pierre HUBERT 2020-06-13 11:40:39 +02:00
parent e9d1bb6e61
commit 9394e6b153
2 changed files with 17 additions and 4 deletions

View File

@ -1,6 +1,8 @@
#include "accounthelper.h"
#include "apirequest.h"
#include "config.h"
#include "loginwindow.h"
#include "refreshservice.h"
#include <QHttpPart>
#include <QNetworkReply>
@ -55,8 +57,19 @@ void APIRequest::onResponse()
int code = mReply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
QByteArray content = mReply->readAll();
emit done(APIResponse(code, content));
deleteLater();
qDebug("Request: %s - %d - %s", mURI.toStdString().c_str(), code, content.toStdString().c_str());
// Check if login token was destroyed
if(code == 412) {
AccountHelper::RemoveLoginToken();
RefreshService::stopService();
LoginWindow().exec();
return;
}
emit done(APIResponse(code, content));
}

View File

@ -6,10 +6,10 @@
WsClient::WsClient(QObject *parent) : QObject(parent)
{
startConnect();
connect(&mWebSocket, &QWebSocket::connected, this, &WsClient::onConnected);
connect(&mWebSocket, &QWebSocket::disconnected, this, &WsClient::onConnectionError);
startConnect();
}
void WsClient::startConnect()