fixed error handling for config import

This commit is contained in:
vladimir.kuznetsov 2024-03-21 23:29:40 +05:00
parent 516e3da7e2
commit 02f186c54e
5 changed files with 7 additions and 8 deletions

View file

@ -79,7 +79,7 @@ bool ImportController::extractConfigFromFile(const QString &fileName)
return extractConfigFromData(data); return extractConfigFromData(data);
} }
emit importErrorOccurred(tr("Unable to open file")); emit importErrorOccurred(tr("Unable to open file"), false);
return false; return false;
} }
@ -117,12 +117,12 @@ bool ImportController::extractConfigFromData(QString data)
if (!m_serversModel->getServersCount()) { if (!m_serversModel->getServersCount()) {
emit restoreAppConfig(config.toUtf8()); emit restoreAppConfig(config.toUtf8());
} else { } else {
emit importErrorOccurred(tr("Invalid configuration file")); emit importErrorOccurred(tr("Invalid configuration file"), false);
} }
break; break;
} }
case ConfigTypes::Invalid: { case ConfigTypes::Invalid: {
emit importErrorOccurred(tr("Invalid configuration file")); emit importErrorOccurred(tr("Invalid configuration file"), false);
break; break;
} }
} }
@ -257,6 +257,7 @@ QJsonObject ImportController::extractWireGuardConfig(const QString &data)
} else { } else {
qDebug() << "Key parameter 'Endpoint' is missing"; qDebug() << "Key parameter 'Endpoint' is missing";
emit importErrorOccurred(errorString(ErrorCode::ImportInvalidConfigError), false); emit importErrorOccurred(errorString(ErrorCode::ImportInvalidConfigError), false);
return QJsonObject();
} }
if (hostNameAndPortMatch.hasCaptured(2)) { if (hostNameAndPortMatch.hasCaptured(2)) {
@ -282,7 +283,7 @@ QJsonObject ImportController::extractWireGuardConfig(const QString &data)
lastConfig[config_key::server_pub_key] = configMap.value("PublicKey"); lastConfig[config_key::server_pub_key] = configMap.value("PublicKey");
} else { } else {
qDebug() << "One of the key parameters is missing (PrivateKey, Address, PublicKey)"; qDebug() << "One of the key parameters is missing (PrivateKey, Address, PublicKey)";
emit importErrorOccurred(errorString(ErrorCode::ImportInvalidConfigError)); emit importErrorOccurred(errorString(ErrorCode::ImportInvalidConfigError), false);
return QJsonObject(); return QJsonObject();
} }

View file

@ -39,7 +39,6 @@ public slots:
signals: signals:
void importFinished(); void importFinished();
void importErrorOccurred(const QString &errorMessage, bool goToPageHome); void importErrorOccurred(const QString &errorMessage, bool goToPageHome);
void importErrorOccurred(const QString &errorMessage);
void qrDecodingFinished(); void qrDecodingFinished();

View file

@ -90,7 +90,7 @@ PageType {
PageController.showBusyIndicator(false) PageController.showBusyIndicator(false)
} }
function onImportErrorOccurred(errorMessage) { function onImportErrorOccurred(errorMessage, goToPageHome) {
PageController.showErrorMessage(errorMessage) PageController.showErrorMessage(errorMessage)
} }
} }

View file

@ -24,7 +24,6 @@ PageType {
} else { } else {
PageController.closePage() PageController.closePage()
} }
PageController.showErrorMessage(errorMessage)
} }
function onImportFinished() { function onImportFinished() {

View file

@ -124,7 +124,7 @@ PageType {
Connections { Connections {
target: ImportController target: ImportController
function onImportErrorOccurred(errorMessage) { function onImportErrorOccurred(errorMessage, goToPageHome) {
PageController.showErrorMessage(errorMessage) PageController.showErrorMessage(errorMessage)
} }
} }