summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorKonstantinos Sideris <sideris.konstantin@gmail.com>2018-05-02 15:30:08 +0300
committerKonstantinos Sideris <sideris.konstantin@gmail.com>2018-05-02 15:30:08 +0300
commit7f69c718143dff456a766c786546a93dd0ee1a75 (patch)
tree3b37cfd9121de5c5c672fb28d17ae895e8fa60b9 /src
parentShow user avatar for messages on different day or time gap > 15 mins (diff)
downloadnheko-7f69c718143dff456a766c786546a93dd0ee1a75.tar.xz
Handle invalid access token
Diffstat (limited to 'src')
-rw-r--r--src/MainWindow.cc5
-rw-r--r--src/MatrixClient.cc19
2 files changed, 20 insertions, 4 deletions
diff --git a/src/MainWindow.cc b/src/MainWindow.cc

index c2353a11..404baec5 100644 --- a/src/MainWindow.cc +++ b/src/MainWindow.cc
@@ -131,6 +131,11 @@ MainWindow::MainWindow(QWidget *parent) SIGNAL(registerSuccess(QString, QString, QString)), this, SLOT(showChatPage(QString, QString, QString))); + connect(client_.data(), &MatrixClient::invalidToken, this, [this]() { + chat_page_->deleteConfigs(); + showLoginPage(); + login_page_->loginError("Invalid token detected. Please try to login again."); + }); QShortcut *quitShortcut = new QShortcut(QKeySequence::Quit, this); connect(quitShortcut, &QShortcut::activated, this, QApplication::quit); diff --git a/src/MatrixClient.cc b/src/MatrixClient.cc
index 5593dbe6..96f8b941 100644 --- a/src/MatrixClient.cc +++ b/src/MatrixClient.cc
@@ -309,13 +309,24 @@ MatrixClient::sync() noexcept reply->deleteLater(); int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); + auto data = reply->readAll(); if (status == 0 || status >= 400) { - qDebug() << reply->errorString(); - return; - } + try { + mtx::errors::Error res = nlohmann::json::parse(data); - auto data = reply->readAll(); + if (res.errcode == mtx::errors::ErrorCode::M_UNKNOWN_TOKEN) { + emit invalidToken(); + return; + } + + emit syncError(QString::fromStdString(res.error)); + + return; + } catch (const nlohmann::json::exception &e) { + qWarning() << e.what(); + } + } try { mtx::responses::Sync response = nlohmann::json::parse(data);