From c2641a5fc2e8e21910375e23012eb542c7563b85 Mon Sep 17 00:00:00 2001 From: Tobias Fella Date: Sat, 2 Dec 2023 21:14:57 +0100 Subject: [PATCH] Cleanup error reporting --- src/controller.cpp | 16 ++++++++-------- src/controller.h | 6 +----- src/login.cpp | 4 ++-- src/neochatconnection.cpp | 4 ++-- src/qml/main.qml | 4 ++-- 5 files changed, 15 insertions(+), 19 deletions(-) diff --git a/src/controller.cpp b/src/controller.cpp index 26c37cfb0..4e031c941 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -227,21 +227,21 @@ void Controller::invokeLogin() }); connect(connection, &NeoChatConnection::loginError, this, [this, connection](const QString &error, const QString &) { if (error == "Unrecognised access token"_ls) { - Q_EMIT errorOccured(i18n("Login Failed: Access Token invalid or revoked")); + Q_EMIT errorOccured(i18n("Login Failed: Access Token invalid or revoked"), {}); connection->logout(false); } else if (error == "Connection closed"_ls) { - Q_EMIT errorOccured(i18n("Login Failed: %1", error)); + Q_EMIT errorOccured(i18n("Login Failed: %1", error), {}); // Failed due to network connection issue. This might happen when the homeserver is // temporary down, or the user trying to re-launch NeoChat in a network that cannot // connect to the homeserver. In this case, we don't want to do logout(). } else { - Q_EMIT errorOccured(i18n("Login Failed: %1", error)); + Q_EMIT errorOccured(i18n("Login Failed: %1", error), {}); connection->logout(true); } Q_EMIT initiated(); }); connect(connection, &NeoChatConnection::networkError, this, [this](const QString &error, const QString &, int, int) { - Q_EMIT errorOccured(i18n("Network Error: %1", error)); + Q_EMIT errorOccured(i18n("Network Error: %1", error), {}); }); connection->assumeIdentity(account.userId(), accessToken); }); @@ -266,17 +266,17 @@ QKeychain::ReadPasswordJob *Controller::loadAccessTokenFromKeyChain(const Accoun switch (job->error()) { case QKeychain::EntryNotFound: - Q_EMIT globalErrorOccured(i18n("Access token wasn't found"), i18n("Maybe it was deleted?")); + Q_EMIT errorOccured(i18n("Access token wasn't found"), i18n("Maybe it was deleted?")); break; case QKeychain::AccessDeniedByUser: case QKeychain::AccessDenied: - Q_EMIT globalErrorOccured(i18n("Access to keychain was denied."), i18n("Please allow NeoChat to read the access token")); + Q_EMIT errorOccured(i18n("Access to keychain was denied."), i18n("Please allow NeoChat to read the access token")); break; case QKeychain::NoBackendAvailable: - Q_EMIT globalErrorOccured(i18n("No keychain available."), i18n("Please install a keychain, e.g. KWallet or GNOME keyring on Linux")); + Q_EMIT errorOccured(i18n("No keychain available."), i18n("Please install a keychain, e.g. KWallet or GNOME keyring on Linux")); break; case QKeychain::OtherError: - Q_EMIT globalErrorOccured(i18n("Unable to read access token"), job->errorString()); + Q_EMIT errorOccured(i18n("Unable to read access token"), job->errorString()); break; default: break; diff --git a/src/controller.h b/src/controller.h index f72438147..cb2ab57d9 100644 --- a/src/controller.h +++ b/src/controller.h @@ -140,11 +140,7 @@ private Q_SLOTS: void setQuitOnLastWindowClosed(); Q_SIGNALS: - /// Error occurred because of user inputs - void errorOccured(const QString &error); - - /// Error occurred because of server or bug in NeoChat - void globalErrorOccured(QString error, QString detail); + void errorOccured(const QString &error, const QString &detail); void syncDone(); void connectionAdded(NeoChatConnection *connection); void connectionDropped(NeoChatConnection *connection); diff --git a/src/login.cpp b/src/login.cpp index 853fb53cd..c13d01e51 100644 --- a/src/login.cpp +++ b/src/login.cpp @@ -82,7 +82,7 @@ void LoginHelper::init() m_connection = nullptr; }); connect(m_connection, &Connection::networkError, this, [this](QString error, const QString &, int, int) { - Q_EMIT Controller::instance().globalErrorOccured(i18n("Network Error"), std::move(error)); + Q_EMIT Controller::instance().errorOccured(i18n("Network Error"), std::move(error)); m_isLoggingIn = false; Q_EMIT isLoggingInChanged(); }); @@ -97,7 +97,7 @@ void LoginHelper::init() }); connect(m_connection, &Connection::resolveError, this, [](QString error) { - Q_EMIT Controller::instance().globalErrorOccured(i18n("Network Error"), std::move(error)); + Q_EMIT Controller::instance().errorOccured(i18n("Network Error"), std::move(error)); }); connectSingleShot(m_connection, &Connection::syncDone, this, [this]() { diff --git a/src/neochatconnection.cpp b/src/neochatconnection.cpp index 7b47ebc5a..0665c2b2e 100644 --- a/src/neochatconnection.cpp +++ b/src/neochatconnection.cpp @@ -194,7 +194,7 @@ void NeoChatConnection::createRoom(const QString &name, const QString &topic, co }); } connect(job, &CreateRoomJob::failure, this, [job] { - Q_EMIT Controller::instance().errorOccured(i18n("Room creation failed: %1", job->errorString())); + Q_EMIT Controller::instance().errorOccured(i18n("Room creation failed: %1", job->errorString()), {}); }); connectSingleShot(this, &Connection::newRoom, this, [](Room *room) { RoomManager::instance().enterRoom(dynamic_cast(room)); @@ -226,7 +226,7 @@ void NeoChatConnection::createSpace(const QString &name, const QString &topic, c }); } connect(job, &CreateRoomJob::failure, this, [job] { - Q_EMIT Controller::instance().errorOccured(i18n("Space creation failed: %1", job->errorString())); + Q_EMIT Controller::instance().errorOccured(i18n("Space creation failed: %1", job->errorString()), {}); }); connectSingleShot(this, &Connection::newRoom, this, [](Room *room) { RoomManager::instance().enterRoom(dynamic_cast(room)); diff --git a/src/qml/main.qml b/src/qml/main.qml index cddddd5cb..d820a4274 100644 --- a/src/qml/main.qml +++ b/src/qml/main.qml @@ -297,8 +297,8 @@ Kirigami.ApplicationWindow { Connections { target: Controller - function onGlobalErrorOccured(error, detail) { - showPassiveNotification(i18n("%1: %2", error, detail)); + function onErrorOccured(error, detail) { + showPassiveNotification(detail.length > 0 ? i18n("%1: %2", error, detail) : error); } function onUserConsentRequired(url) {