From 02f186c54ef54cf61cb3bf1056667ec93abbd5cc Mon Sep 17 00:00:00 2001 From: "vladimir.kuznetsov" Date: Thu, 21 Mar 2024 23:29:40 +0500 Subject: [PATCH] fixed error handling for config import --- client/ui/controllers/importController.cpp | 9 +++++---- client/ui/controllers/importController.h | 1 - client/ui/qml/Pages2/PageSetupWizardStart.qml | 2 +- client/ui/qml/Pages2/PageSetupWizardViewConfig.qml | 1 - client/ui/qml/Pages2/PageStart.qml | 2 +- 5 files changed, 7 insertions(+), 8 deletions(-) diff --git a/client/ui/controllers/importController.cpp b/client/ui/controllers/importController.cpp index 098d77a72..3c73e0df6 100644 --- a/client/ui/controllers/importController.cpp +++ b/client/ui/controllers/importController.cpp @@ -79,7 +79,7 @@ bool ImportController::extractConfigFromFile(const QString &fileName) return extractConfigFromData(data); } - emit importErrorOccurred(tr("Unable to open file")); + emit importErrorOccurred(tr("Unable to open file"), false); return false; } @@ -117,12 +117,12 @@ bool ImportController::extractConfigFromData(QString data) if (!m_serversModel->getServersCount()) { emit restoreAppConfig(config.toUtf8()); } else { - emit importErrorOccurred(tr("Invalid configuration file")); + emit importErrorOccurred(tr("Invalid configuration file"), false); } break; } case ConfigTypes::Invalid: { - emit importErrorOccurred(tr("Invalid configuration file")); + emit importErrorOccurred(tr("Invalid configuration file"), false); break; } } @@ -257,6 +257,7 @@ QJsonObject ImportController::extractWireGuardConfig(const QString &data) } else { qDebug() << "Key parameter 'Endpoint' is missing"; emit importErrorOccurred(errorString(ErrorCode::ImportInvalidConfigError), false); + return QJsonObject(); } if (hostNameAndPortMatch.hasCaptured(2)) { @@ -282,7 +283,7 @@ QJsonObject ImportController::extractWireGuardConfig(const QString &data) lastConfig[config_key::server_pub_key] = configMap.value("PublicKey"); } else { qDebug() << "One of the key parameters is missing (PrivateKey, Address, PublicKey)"; - emit importErrorOccurred(errorString(ErrorCode::ImportInvalidConfigError)); + emit importErrorOccurred(errorString(ErrorCode::ImportInvalidConfigError), false); return QJsonObject(); } diff --git a/client/ui/controllers/importController.h b/client/ui/controllers/importController.h index a8d911246..95af9f35e 100644 --- a/client/ui/controllers/importController.h +++ b/client/ui/controllers/importController.h @@ -39,7 +39,6 @@ public slots: signals: void importFinished(); void importErrorOccurred(const QString &errorMessage, bool goToPageHome); - void importErrorOccurred(const QString &errorMessage); void qrDecodingFinished(); diff --git a/client/ui/qml/Pages2/PageSetupWizardStart.qml b/client/ui/qml/Pages2/PageSetupWizardStart.qml index b12589c87..b4d863266 100644 --- a/client/ui/qml/Pages2/PageSetupWizardStart.qml +++ b/client/ui/qml/Pages2/PageSetupWizardStart.qml @@ -90,7 +90,7 @@ PageType { PageController.showBusyIndicator(false) } - function onImportErrorOccurred(errorMessage) { + function onImportErrorOccurred(errorMessage, goToPageHome) { PageController.showErrorMessage(errorMessage) } } diff --git a/client/ui/qml/Pages2/PageSetupWizardViewConfig.qml b/client/ui/qml/Pages2/PageSetupWizardViewConfig.qml index fa40280bf..6dc3ebce7 100644 --- a/client/ui/qml/Pages2/PageSetupWizardViewConfig.qml +++ b/client/ui/qml/Pages2/PageSetupWizardViewConfig.qml @@ -24,7 +24,6 @@ PageType { } else { PageController.closePage() } - PageController.showErrorMessage(errorMessage) } function onImportFinished() { diff --git a/client/ui/qml/Pages2/PageStart.qml b/client/ui/qml/Pages2/PageStart.qml index c30f9b5d3..ee4001a04 100644 --- a/client/ui/qml/Pages2/PageStart.qml +++ b/client/ui/qml/Pages2/PageStart.qml @@ -124,7 +124,7 @@ PageType { Connections { target: ImportController - function onImportErrorOccurred(errorMessage) { + function onImportErrorOccurred(errorMessage, goToPageHome) { PageController.showErrorMessage(errorMessage) } }