Retry initial sync only on specific errors

fixes #233
fixes #89
This commit is contained in:
Konstantinos Sideris 2018-03-04 14:49:15 +02:00
parent 7fc33a71fd
commit 0f62cba498
4 changed files with 19 additions and 8 deletions

View file

@ -128,7 +128,7 @@ private:
template<class Collection>
void updateUserMetadata(const std::vector<Collection> &collection);
void retryInitialSync();
void retryInitialSync(int status_code = -1);
//! Update the room with the new notification count.
void updateRoomNotificationCount(const QString &room_id, uint16_t notification_count);

View file

@ -147,7 +147,7 @@ signals:
void getOwnProfileResponse(const QUrl &avatar_url, const QString &display_name);
void getOwnCommunitiesResponse(const QList<QString> &own_communities);
void initialSyncCompleted(const mtx::responses::Sync &response);
void initialSyncFailed();
void initialSyncFailed(int status_code = -1);
void syncCompleted(const mtx::responses::Sync &response);
void syncFailed(const QString &msg);
void joinFailed(const QString &msg);

View file

@ -361,7 +361,7 @@ ChatPage::ChatPage(QSharedPointer<MatrixClient> client,
});
initialSyncTimer_ = new QTimer(this);
connect(initialSyncTimer_, &QTimer::timeout, this, &ChatPage::retryInitialSync);
connect(initialSyncTimer_, &QTimer::timeout, this, [this]() { retryInitialSync(); });
syncTimeoutTimer_ = new QTimer(this);
connect(syncTimeoutTimer_, &QTimer::timeout, this, [this]() {
@ -965,19 +965,30 @@ ChatPage::setGroupViewState(bool isEnabled)
}
void
ChatPage::retryInitialSync()
ChatPage::retryInitialSync(int status_code)
{
initialSyncTimer_->stop();
if (client_->getHomeServer().isEmpty()) {
deleteConfigs();
resetUI();
emit showLoginPage("Sync error. Please try again.");
return;
}
qWarning() << "Retrying initial sync";
// Retry on Bad-Gateway & Gateway-Timeout errors
if (status_code == -1 || status_code == 504 || status_code == 502 || status_code == 524) {
qWarning() << "retrying initial sync";
client_->initialSync();
initialSyncTimer_->start(INITIAL_SYNC_RETRY_TIMEOUT);
client_->initialSync();
initialSyncTimer_->start(INITIAL_SYNC_RETRY_TIMEOUT);
} else {
// Drop into the login screen.
deleteConfigs();
resetUI();
emit showLoginPage(QString("Sync error %1. Please try again.").arg(status_code));
}
}
void

View file

@ -401,7 +401,7 @@ MatrixClient::initialSync() noexcept
if (status == 0 || status >= 400) {
qDebug() << "Error code received" << status;
emit initialSyncFailed();
emit initialSyncFailed(status);
return;
}