From 9394e6b153ee4f9325c4caea57b368dde0648951 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Sat, 13 Jun 2020 11:40:39 +0200 Subject: [PATCH] Handle the case login tokens are destroyed --- apirequest.cpp | 17 +++++++++++++++-- wsclient.cpp | 4 ++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/apirequest.cpp b/apirequest.cpp index f4f1246..48d557f 100644 --- a/apirequest.cpp +++ b/apirequest.cpp @@ -1,6 +1,8 @@ #include "accounthelper.h" #include "apirequest.h" #include "config.h" +#include "loginwindow.h" +#include "refreshservice.h" #include #include @@ -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)); + } diff --git a/wsclient.cpp b/wsclient.cpp index ffb89a8..744b0f0 100644 --- a/wsclient.cpp +++ b/wsclient.cpp @@ -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()