Handle invalid access token
This commit is contained in:
parent
23accc50d6
commit
7f69c71814
@ -81,6 +81,7 @@ public:
|
||||
|
||||
QSharedPointer<UserSettings> userSettings() { return userSettings_; }
|
||||
QSharedPointer<Cache> cache() { return cache_; }
|
||||
void deleteConfigs();
|
||||
|
||||
signals:
|
||||
void contentLoaded();
|
||||
@ -126,7 +127,6 @@ private:
|
||||
void updateTypingUsers(const QString &roomid, const std::vector<std::string> &user_ids);
|
||||
|
||||
void loadStateFromCache();
|
||||
void deleteConfigs();
|
||||
void resetUI();
|
||||
//! Decides whether or not to hide the group's sidebar.
|
||||
void setGroupViewState(bool isEnabled);
|
||||
|
@ -175,6 +175,8 @@ signals:
|
||||
|
||||
void redactionFailed(const QString &error);
|
||||
void redactionCompleted(const QString &room_id, const QString &event_id);
|
||||
void invalidToken();
|
||||
void syncError(const QString &error);
|
||||
|
||||
private:
|
||||
QNetworkReply *makeUploadRequest(QSharedPointer<QIODevice> iodev);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user